TCS Coding Test Questions with Solutions (2026 Pattern)
The TCS coding round tests 2 problems in 45 minutes. Covers question patterns, worked solutions in Python, and how test-case scoring works in TCS campus drives.
The TCS coding round presents 2 problems in a 45-minute window, graded by an automated test suite that runs your code against hidden inputs and scores each test case independently.
The Coding Round at a Glance
The coding component sits inside the TCS NQT as a separate module. For the full NQT structure (section-wise time splits, eligibility cutoffs, and track differences), the TCS NQT aptitude questions guide covers those details. This article focuses on the coding module specifically.
Register for TCS campus recruitment through TCS NextStep when the hiring cycle opens for your graduation year.
| Detail | Value |
|---|---|
| Problems | 2 |
| Time limit | 45 minutes (shared) |
| Languages | C, C++, Java, Python |
| Environment | Browser-based IDE (provided by TCS) |
| Input/output | Standard stdin and stdout |
| Scoring | Partial marks per test case passed |
No external libraries, no file I/O, no interactive prompts in the output. Your program reads from stdin and writes results to stdout. Any extra output will fail every test case: a prompt like “Enter a number:” left in the code, a trailing newline, or an extra space.
Four Problem Types That Recur
TCS coding questions draw from a predictable set of patterns. Four types show up consistently across published papers and candidate reports.
String Manipulation
This is the most common type at the easier difficulty level. Tasks involve scanning characters and classifying or replacing them based on simple rules. Typical variants: replace all vowels with a symbol, replace all consonants with a different symbol, convert case, reverse a string with a delimiter. No complex data structures needed. One loop, a character-classification condition, and clean output.
Series and Math Patterns
TCS favours interleaved-series problems: two sequences merged into one, where odd-indexed and even-indexed terms follow different rules. The Fibonacci-prime interleaving in the worked solution below is the most widely cited example. Number theory basics (prime checking, modular arithmetic, Fibonacci generation) appear inside these problems and also as standalone questions. The key skill is identifying the underlying sequence before writing any code.
Simple Dynamic Programming
DP problems at TCS are typically one-dimensional and follow a recurrence close to Fibonacci. Count ways to climb N stairs (taking 1 or 2 steps at a time) is the standard template. No two-dimensional tables, no graph traversal, no complex memoisation in the standard Ninja-track paper. Recognising that the recurrence is dp[i] = dp[i-1] + dp[i-2] handles most of these problems.
Greedy and Array Problems
The second problem slot sometimes uses a greedy scan or array manipulation: reverse an array, find the maximum subarray, count pairs meeting a condition. These require clean loop handling and attention to index boundaries. The difficulty comes from edge cases (empty array, N equal to 1) rather than algorithmic complexity.
Three Worked Solutions with Code
The three problems below cover the most common pattern types. Solutions are in Python for readability. The same logic works in Java or C++ with equivalent syntax.
Worked Solution 1: Three-String Transformation
- Problem: Given three strings as input, apply separate transformations to each: replace vowels with
#in the first string, replace consonants with*in the second string, convert all characters to uppercase in the third string. - Sample input: s1 =
FACEPREP, s2 =hello, s3 =world - Expected output:
F#C#PR#P/*e**o/WORLD
Trace for s1 (FACEPREP):
- F is a consonant, stays F
- A is a vowel, becomes
# - C stays C; E becomes
#; P stays P; R stays R; E becomes#; P stays P - Result:
F#C#PR#P✓
Trace for s2 (hello):
- h is a consonant, becomes
*; e is a vowel, stays e; l becomes*; l becomes*; o is a vowel, stays o - Result:
*e**o✓
def transform_strings():
s1 = input()
s2 = input()
s3 = input()
vowels = set('aeiouAEIOU')
out1 = ''.join('#' if c in vowels else c for c in s1)
out2 = ''.join('*' if c.isalpha() and c not in vowels else c for c in s2)
out3 = s3.upper()
print(out1)
print(out2)
print(out3)
transform_strings()
- Edge case: digits and spaces in s2 should pass through unchanged, not become
*. Thec.isalpha()guard handles this.
Worked Solution 2: Fibonacci-Prime Interleaved Series
- Problem: The series below merges two sequences: odd-indexed positions hold Fibonacci numbers, even-indexed positions hold prime numbers.
- Series: 1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …
- Task: Given N (1-indexed), find the Nth term.
Position-by-position trace:
- Position 1 (odd): Fibonacci index 0 = 1
- Position 2 (even): Prime index 0 = 2
- Position 3 (odd): Fibonacci index 1 = 1
- Position 4 (even): Prime index 1 = 3
- Position 5 (odd): Fibonacci index 2 = 2
- Position 6 (even): Prime index 2 = 5
- Position 10 (even): Prime index 4 = 11 ✓
The mapping: odd position k uses fib[k // 2]; even position k uses primes[k // 2 - 1]. Both are zero-indexed.
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def nth_term(n):
fib = [1, 1]
while len(fib) < n:
fib.append(fib[-1] + fib[-2])
primes = []
candidate = 2
while len(primes) < n:
if is_prime(candidate):
primes.append(candidate)
candidate += 1
if n % 2 != 0: # odd position: Fibonacci
return fib[n // 2]
else: # even position: prime
return primes[n // 2 - 1]
n = int(input())
print(nth_term(n))
- Why generate more elements than needed? The loop builds
nFibonacci numbers andnprimes, which is more than necessary for any single call tonth_term(n). Slightly wasteful on memory but guaranteed not to go out of bounds.
Worked Solution 3: Count Ways to Climb N Stairs
- Problem: You are climbing a staircase. Each move can cover 1 step or 2 steps. How many distinct ways can you reach step N?
- Sample: N = 4 → 5 ways: (1,1,1,1), (1,1,2), (1,2,1), (2,1,1), (2,2)
DP trace for N = 4:
dp[1]= 1dp[2]= 2dp[3]=dp[2]+dp[1]= 3dp[4]=dp[3]+dp[2]= 5 ✓
def count_ways(n):
if n <= 1:
return 1
dp = [0] * (n + 1)
dp[1] = 1
dp[2] = 2
for i in range(3, n + 1):
dp[i] = dp[i - 1] + dp[i - 2]
return dp[n]
n = int(input())
print(count_ways(n))
- Pattern note: The recurrence
dp[i] = dp[i-1] + dp[i-2]matches the Fibonacci structure. Any TCS problem framed as “count distinct ways with two choices at each step” follows this template directly. Recognise the pattern, implement the array, handle the base cases.
How TCS Scores the Coding Round
TCS runs your submission against a hidden test suite. Each problem has multiple test cases covering standard inputs and edge cases. The current NQT coding section awards partial marks per test case your solution passes. A solution that handles 5 of 8 test cases earns partial credit for those 5.
Before the NQT model was introduced, TCS campus coding rounds scored problems on an all-or-nothing basis per problem. A compile error, or a solution that failed the first test case, earned zero. Some off-campus drives still use this stricter pattern. The TCS NQT test pattern guide explains how track selection (Ninja, Digital, Prime) connects to the NQT scoring tiers.
Two submission rules that affect your score:
- Always submit something. A brute-force solution that passes basic cases is worth more than a polished solution left blank. If your O(n squared) approach handles 5 test cases, submit it. You can refine in remaining time.
- Print exactly what the spec asks. No prompts like “Enter a number:”. No trailing spaces. No extra newlines. Any extra output fails every test case, regardless of whether the underlying logic is correct.
For five more worked NQT coding problems (palindrome, base-17, digit-position difference, prime range, array reversal), the TCS coding questions and answers guide is the companion resource.
Building Coding Speed Before the Test
The 45-minute window is tight if you are still thinking in pseudocode. A workable threshold for the Ninja track: solve one easy string or series problem in under 15 minutes, leaving 25 to 30 minutes for the harder second problem. That ratio only holds if the basic patterns are automatic.
Three practice targets that move the needle:
- String traversal first. Drill
''.join(...), character classification withstr.isalpha(), and case conversion until they require no thought. Most TCS string problems are single-loop problems with a classification condition inside. - Prime-check template. Trial division up to the square root of n is the standard approach. It appears inside at least half of TCS series problems that involve primes. Know it cold.
- Trace before you type. For series problems, write the first 6 terms on paper, confirm the odd/even index mapping, then open the IDE. Two minutes of tracing prevents ten minutes of off-by-one debugging.
The TCS Ninja mock test guide includes timed practice under conditions close to the real test environment.
In FY26, TCS CHRO Sudeep Kunnumal reported that 60% of TCS fresher hires are AI-skilled, up from 10 to 15% three years ago. That figure matters most for TCS Prime (up to Rs 11 LPA), where an AI or data project review now sits alongside the coding gate. Clearing the coding round gets you through Ninja. Adding one small, deployed AI project shifts the track to Prime.
TinkerLLM is the lowest-friction way to build that project: Rs 299 to go from reading about LLMs to shipping a working LLM-powered tool, which is the kind of concrete output TCS Prime interviewers ask about.
Primary sources
Frequently asked questions
How many coding problems are in the TCS coding test?
The TCS coding round has 2 problems with a shared 45-minute time limit. Both are graded by an automated test suite. One problem is typically easier, the other moderate in difficulty.
Which programming languages are allowed in the TCS coding test?
TCS allows C, C++, Java, and Python in the coding round. Python is the most common choice for freshers because its string and list syntax is concise and readable under time pressure.
Is there partial credit in the TCS coding round?
The current NQT coding section awards partial marks for each test case your solution passes, even if the full solution is incomplete. Older TCS campus coding tests before NQT scored on an all-or-nothing basis per problem.
What types of problems appear in the TCS coding test?
String manipulation, series and pattern recognition, basic math, and simple data structure operations are the most frequent types. Simple dynamic programming problems appear at the moderate-difficulty level.
How do I prepare for TCS coding questions in 2 weeks?
Focus on string traversal, number theory basics (prime check, Fibonacci), and one-dimensional DP problems like staircase counting. Practice writing clean code that handles edge cases such as empty input or N equal to zero.
Does TCS coding test use an online IDE?
Yes. TCS provides a browser-based IDE for the coding round. You write, compile, and run code directly in the browser. No local setup is required. Input and output go through standard stdin and stdout.
How is the TCS coding section different from the TCS aptitude sections?
The aptitude sections test verbal, numerical, and reasoning ability through multiple-choice questions. The coding section requires writing a working program from scratch in an IDE. They are separate modules within the TCS NQT with their own time windows.
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)