Company Corner

TCS Coding Questions and Answers (2026 Guide)

Five worked TCS NQT coding problems with hand-traced Python solutions. Covers palindrome check, base-17 conversion, digit sums, prime range, and array reversal.

By FACE Prep Team 7 min read
tcs tcs-nqt coding-questions placement-prep python company-corner

The TCS NQT Coding Section gives you 2 questions and 45 minutes to write working code in C, C++, Java, or Python.

The TCS NQT Coding Section at a Glance

This section is one module inside the broader TCS NQT. For the full test structure, including section-wise time splits, cutoff scores, and eligibility criteria, the TCS NQT aptitude questions guide covers those details.

What matters here: two problems, one online judge, and an auto-graded test suite that scores based on how many hidden test cases your solution passes. Partial marks are possible: a solution that handles the basic cases but fails edge cases still scores better than a blank submission.

DetailValue
Number of problems2
Time limit45 minutes
Languages supportedC, C++, Java, Python
Scoring methodPartial marks per test case passed

Register for the NQT through TCS NextStep when the hiring cycle opens for your graduation year.

Five Worked TCS Coding Problems

The five problems below cover the core pattern types that appear repeatedly in published TCS NQT papers. Solutions are in Python for readability. The same logic applies in C++, Java, or C with minor syntax changes.

Problem 1: Palindrome Number Check

A number is a palindrome if it reads the same forwards and backwards. The task: given a positive integer, confirm whether it is a palindrome.

  • Input: 121
  • Expected output: 121 is a palindrome

The approach is to extract digits in reverse order using repeated modulo and integer division, then compare the reversed number to the original.

n = int(input())
original = n
rev = 0
while n > 0:
    rev = rev * 10 + n % 10
    n //= 10
if original == rev:
    print(f"{original} is a palindrome")
else:
    print(f"{original} is not a palindrome")

Hand-traced for input 121:

  • Step 1: rev = 0 x 10 + (121 mod 10) = 1; remaining n = 12
  • Step 2: rev = 1 x 10 + (12 mod 10) = 12; remaining n = 1
  • Step 3: rev = 12 x 10 + (1 mod 10) = 121; remaining n = 0
  • Loop ends. original (121) equals rev (121): output “121 is a palindrome” ✓

For input 123, the reversed value is 321, which does not equal 123, so the output is “123 is not a palindrome”.

Problem 2: Base-17 to Decimal Conversion (Sweet Seventeen)

Base 17 extends the standard decimal digits (0 to 9) with letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15, G = 16. The task: convert a base-17 string to its decimal equivalent.

  • Input: 23GF
  • Expected output: 10980

The approach is Horner’s method: process each character left to right, multiplying the running result by 17 and adding the digit’s value at each step.

def to_decimal(s):
    mapping = {}
    for i in range(10):
        mapping[str(i)] = i
    for i, ch in enumerate('ABCDEFG'):
        mapping[ch] = 10 + i
    result = 0
    for ch in s:
        result = result * 17 + mapping[ch]
    return result

print(to_decimal(input()))

Hand-traced for input “23GF”:

  • Start: result = 0
  • Character ‘2’ (value 2): result = 0 x 17 + 2 = 2
  • Character ‘3’ (value 3): result = 2 x 17 + 3 = 37
  • Character ‘G’ (value 16): result = 37 x 17 + 16 = 629 + 16 = 645
  • Character ‘F’ (value 15): result = 645 x 17 + 15 = 10965 + 15 = 10980

Cross-check using positional weights: 2 x 4913 + 3 x 289 + 16 x 17 + 15 x 1 = 9826 + 867 + 272 + 15 = 10980 ✓

Problem 3: Digit-Position Difference (Oddly Even)

Given a number of up to 100 digits, compute the absolute difference between the sum of digits at odd positions and the sum of digits at even positions, counting positions from the left starting at 1.

  • Input: 4567
  • Expected output: 2

Because the input can be 100 digits long, it must be treated as a string, not a numeric type.

s = input()
odd_sum = sum(int(s[i]) for i in range(0, len(s), 2))
even_sum = sum(int(s[i]) for i in range(1, len(s), 2))
print(abs(odd_sum - even_sum))

Hand-traced for input “4567”:

  • Odd positions (1, 3) map to 0-indexed (0, 2): s[0] = 4, s[2] = 6; odd_sum = 10
  • Even positions (2, 4) map to 0-indexed (1, 3): s[1] = 5, s[3] = 7; even_sum = 12
  • abs(10 - 12) = 2; output: 2 ✓

This matches the expected output from the original problem statement.

Problem 4: Sum of Primes in a Range

Given two integers a and b, find the sum of all prime numbers in the range from a to b, inclusive.

  • Input: 1 10
  • Expected output: 17

The approach is trial division for each candidate number, checking divisibility only up to the square root of the candidate.

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

a, b = map(int, input().split())
print(sum(i for i in range(a, b + 1) if is_prime(i)))

Hand-traced for a = 1, b = 10:

  • 1: less than 2, not prime
  • 2: divisor loop is empty (upper bound rounds to 1), prime
  • 3: divisor loop is empty (upper bound rounds to 1), prime
  • 4: 4 divided by 2 leaves no remainder, not prime
  • 5: no divisors found up to 2, prime
  • 6: 6 divided by 2 leaves no remainder, not prime
  • 7: no divisors found up to 2, prime
  • 8: 8 divided by 2 leaves no remainder, not prime
  • 9: 9 divided by 3 leaves no remainder, not prime
  • 10: 10 divided by 2 leaves no remainder, not prime
  • Primes found: 2, 3, 5, 7; sum = 2 + 3 + 5 + 7 = 17 ✓

Problem 5: Reverse an Array

Given n integers on one line, print them in reverse order.

  • Input: 5 integers: 1 2 3 4 5
  • Expected output: 5 4 3 2 1

The approach is a two-pointer in-place swap, moving from both ends of the array towards the centre.

n = int(input())
arr = list(map(int, input().split()))
for i in range(n // 2):
    arr[i], arr[n - 1 - i] = arr[n - 1 - i], arr[i]
print(*arr)

Hand-traced for n = 5, arr = [1, 2, 3, 4, 5]:

  • i = 0: swap positions 0 and 4 — arr becomes [5, 2, 3, 4, 1]
  • i = 1: swap positions 1 and 3 — arr becomes [5, 4, 3, 2, 1]
  • Loop ends after i = 1 (range covers only 0 and 1 for n = 5)
  • Output: 5 4 3 2 1 ✓

How to Approach TCS Coding Questions

Pattern recognition before writing code. Before touching the keyboard, identify which category the problem belongs to:

  • Reverse or compare: palindrome check, reverse array, mirror string operations
  • Positional digit operations: digit-position sums, alternating weighted sums
  • Number theory: prime check, divisibility testing, base conversion
  • Simulation: walk problems, candy/queue distributions, refill cycles

Once the category is clear, the algorithm follows directly. Palindrome problems resolve with a digit-extraction loop or a string slice comparison. Base conversion problems resolve cleanly with Horner’s method, as in Problem 2 above. Prime-testing problems need trial division only up to the square root, which is efficient enough for any constraint TCS NQT sets in standard Ninja-level problems.

Edge cases are where submissions drop marks. Three to check on every TCS NQT problem:

  • Zero and one are not prime. The is_prime function above handles both with the n < 2 guard at the top.
  • Single-digit palindromes. Any single digit is a palindrome by definition. The loop runs zero iterations and the original equals the reversed value.
  • Large-number string inputs. The Oddly Even problem explicitly allows inputs up to 100 digits. A standard integer type overflows well before that. Always read such inputs as a string, as in Problem 3.

Python is the fastest language to write during a timed test, and TCS NQT accepts it. The one practical note: the judge runs Python 3, so use int(input()) for integer input and input().split() for space-separated values. Python 2 syntax (raw_input) will fail on the judge.

Partial marks matter more than many students realise. TCS NQT awards marks per test case passed, not all-or-nothing. A solution that correctly handles the sample cases but fails edge cases still scores more than a blank submission. The strategy: write a working solution first, then add edge-case handling if time permits.

For a complete breakdown of the TCS Ninja-track question format and scoring structure, the TCS Ninja test pattern article covers the full structure. Combine coding practice with TCS aptitude test practice, as both sections feed into the NQT rank that determines your track.

AI Skills and TCS Hiring in 2026

The coding gate has not changed. Two problems, 45 minutes, same format as the Ninja track has used for several years.

What has changed is the tier above it. TCS CHRO Sudeep Kunnumal reported at the AI Impact Summit in March 2026 that 60% of FY26 fresher hires are AI-skilled, up from 10 to 15% three years earlier, with Prime and Digital cadre volumes rising 50% in the same period.

Three hiring tracks, three sets of requirements:

TrackCTC bandWhat the selection adds
TCS Ninja₹3.5–3.9 LPANQT pass + basic coding (this guide covers it)
TCS Digital₹7–7.5 LPAHigher NQT cutoff + advanced technical round
TCS Prime₹9–11 LPATop NQT performance + AI/data project review

The problems in this guide cover the Ninja gate. Moving to Prime adds one concrete layer on top: a deployed AI or data project that demonstrates the ability to build something functional, not just solve a whiteboard problem. Coding fundamentals are the prerequisite; the project work is the differentiator.

The AI skills roadmap maps out what that build path looks like from the current year of study through placement season, including which tools and frameworks TCS Prime interviewers have asked about in recent cycles.

TinkerLLM at ₹299 is where most students run their first AI experiment.

Primary sources

Frequently asked questions

How many coding questions are in TCS NQT?

The TCS NQT Coding Section has 2 questions with a combined time limit of 45 minutes. Each question is scored based on test cases passed.

Which programming languages are allowed in TCS NQT?

TCS NQT allows C, C++, Java, and Python. PERL appeared on older test patterns but has been phased out of current papers.

Is the TCS NQT coding section hard?

Difficulty is moderate for most Ninja-track questions. Problems typically test one core algorithm such as loops, string manipulation, or basic data structures rather than graph or dynamic-programming complexity.

What is the base-17 digit mapping used in Sweet Seventeen?

Base 17 uses 0 to 9 as standard digits and A=10, B=11, C=12, D=13, E=14, F=15, G=16. The digit G is the largest single digit in this system.

Does solving TCS Ninja coding questions prepare you for TCS Digital?

Ninja-track coding is a prerequisite, but TCS Digital typically adds one harder problem or a stricter efficiency constraint. Ninja prep gets you through the gate; Digital needs one extra layer of data-structure practice.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF