Company Corner

TCS Sample Coding Questions: Practice Problems and Worked Solutions

Representative TCS NQT coding problems with verified C and Python solutions. Covers conceptual MCQs, worked coding patterns, and the 2026 track structure.

By FACE Prep Team 6 min read
tcs tcs-nqt coding-questions placement-prep c-programming python worked-solutions

TCS NQT’s Advanced section includes one hands-on coding problem for every candidate shortlisted for Digital or Prime track consideration.

TCS does not publish official question papers after each drive. The problems that appear in the Advanced section are drawn from a consistent pool: number theory, string operations, basic array logic, and recursion. The sample questions below match those repeating patterns. Every output has been re-derived from first principles. Legacy sources have circulated wrong answers on TCS problems before.

TCS NQT Coding Section: What You Are Actually Tested On

The written test that screens TCS campus candidates is called the TCS NQT (National Qualifier Test). It has two parts with different audiences. For a detailed breakdown of the test structure and Ninja-track sections, see the TCS Ninja Test Pattern guide.

SectionTrackContentDuration
FoundationAll tracksVerbal (24Q), Reasoning (30Q), Numerical (26Q)120 min
AdvancedDigital and Prime shortlistingProgramming Logic (10Q) + Coding (1–2 problems)60 min

A few points that regularly confuse candidates:

  • The Ninja track is evaluated solely on Foundation scores. The coding problem is not part of Ninja shortlisting.
  • The Advanced section’s coding problem accepts C, C++, Java, or Python. You choose at the start of that section.
  • No negative marking applies in Foundation. Advanced section penalties vary by drive — check the TCS iON notification.

CTC bands by track (current 2026 hiring cycle):

TrackCTC (LPA)
NinjaRs 3.5 to 3.9
DigitalRs 7.0 to 7.5
PrimeRs 9.0 to 11.0

Conceptual C Questions

The Programming Logic sub-section of the Advanced round includes multiple-choice questions on C and basic programming concepts. These four types appear consistently.

  • Q1. What is the output of the following code?
#include <stdio.h>
void main() {
    int k = 5;
    int *p = &k;
    int **m = &p;
    printf("%d %d %d\n", k, *p, **m);
}
  • a) 5 5 5

  • b) 5 5 junk

  • c) 5 junk junk

  • d) Compile-time error

  • Answer: a. k holds 5. p points to k, so *p dereferences to 5. m points to p, so *m gives p, and **m gives *p which gives 5. All three print the value 5.

  • Q2. Which of the following statements about C are correct?

      1. The main() function must always be the first function defined in a C program.
      1. All members of a union share the same memory location.
      1. A void pointer can store the address of any data type and be typecasted before dereferencing.
      1. A static variable holds a random junk value if not explicitly initialised.
    • a) 2, 3

    • b) 1, 2

    • c) 1, 2, 3

    • d) 1, 2, 3, 4

  • Answer: a. Statement 2 is correct (union members share memory by definition). Statement 3 is correct (void pointer is a generic pointer, must be cast before use). Statement 1 is false (main() can appear anywhere; the compiler searches by name). Statement 4 is false (static variables are zero-initialised by the C standard).

  • Q3. If a function is defined as static in C, what does that mean?

    • a) The return value of the function remains unchanged across calls.
    • b) All local variables inside the function are automatically initialised to zero.
    • c) The function can only be accessed within the same source file.
    • d) The static keyword cannot be applied to functions.
  • Answer: c. A static function has file-level linkage, making it invisible to other translation units. This is independent of static local variables, which is a separate use of the same keyword.

  • Q4. What is the behaviour of this loop?

while (0 == 0) { }
  • a) Syntax error (empty braces)

  • b) Infinite loop

  • c) Exits immediately because 0 == 0 evaluates to false

  • d) Syntax error (same number compared to itself)

  • Answer: b. The expression 0 == 0 evaluates to 1 (true) in C. The loop condition is always satisfied and the loop runs indefinitely. Empty braces are valid C syntax.

Worked Coding Problems

The hands-on coding problem in the Advanced section is typically one of these three difficulty levels: a clean mathematical computation, a string operation, or a simple array traversal. Three representative problems follow, with solutions in C and Python.

Factorial of N

  • Problem: Write a program to compute the factorial of a non-negative integer N.
  • Input: A single integer N (command-line argument).
  • Output: The factorial of N, as a single integer.
  • Example: Input: 5, Output: 120
  • Verify: 5 × 4 × 3 × 2 × 1 = 120

C solution:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    int n = atoi(argv[1]);
    long long fact = 1;
    int i;
    for (i = 2; i <= n; i++) {
        fact *= i;
    }
    printf("%lld\n", fact);
    return 0;
}

Python solution:

import sys
n = int(sys.argv[1])
result = 1
for i in range(2, n + 1):
    result *= i
print(result)

Reverse a Number

  • Problem: Write a program to print the digits of an integer in reverse order.
  • Input: A single integer N (command-line argument).
  • Output: The reversed integer.
  • Example: Input: 12345, Output: 54321
  • Verify: Extract digits right to left: 5, then 4, then 3, then 2, then 1. Build result: 5 → 54 → 543 → 5432 → 54321.

C solution:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    int n = atoi(argv[1]);
    int rev = 0;
    while (n > 0) {
        rev = rev * 10 + n % 10;
        n /= 10;
    }
    printf("%d\n", rev);
    return 0;
}

Python solution:

import sys
n = sys.argv[1]
print(int(n[::-1]))

Triangle Area

  • Problem: Write a program to compute the area of a triangle given base and height.
  • Input: Two positive integers representing the base and height (command-line arguments).
  • Output: Area as a floating-point number rounded to two decimal places. Do not use scientific notation.
  • Example: Input: 10 5, Output: 25.00
  • Verify: Area = (1/2) × 10 × 5 = 25.00

C solution:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    double base = atof(argv[1]);
    double height = atof(argv[2]);
    double area = 0.5 * base * height;
    printf("%.2f\n", area);
    return 0;
}

Recurring Patterns and What to Practice

Across TCS NQT drives from 2022 to 2025, six topic clusters cover the majority of coding and Programming Logic questions:

  • Number theory: factorial, prime check, Armstrong numbers, GCD and LCM
  • String operations: reversal, palindrome check, vowel count, anagram detection
  • Pattern printing: triangles, diamonds, and number patterns using nested loops
  • Array basics: finding second largest, removing duplicates, array rotation
  • Recursion: Fibonacci series, sum of digits, power computation
  • Pointer and memory concepts: pointer arithmetic, union behaviour, static scope

For aptitude preparation alongside the coding section, FACE Prep’s TCS NQT aptitude question bank covers the Foundation section in depth. For the quantitative reasoning topics specifically, see the TCS aptitude questions practice set.

TCS, AI Skills, and the Prime Track in 2026

The coding bar in the NQT matters at the entry level. The track you reach, and the CTC that follows, depends on how that score is applied.

In FY26, 60% of TCS fresher hires are AI-skilled, up from 10 to 15% three years ago, according to TCS CHRO Sudeep Kunnumal at the AI Impact Summit in March 2026 (Rediff/Business Standard). TCS has simultaneously reduced its FY27 fresher intake to approximately 25,000 from 44,000 in FY26, while tilting the mix further toward AI-skilled candidates (Financial Express).

The Prime track, at Rs 9 to 11 LPA, now includes an extended technical interview that reviews an AI or data project. The logic skills this article practises (recursion, array traversal, clean code structure) are the same foundations that AI project work requires.

Clearing the Ninja-track coding bar is one thing. Competing for Prime means showing a project. TinkerLLM at ₹299 is a hands-on starting point: structured LLM exercises that move from reading API docs to shipping a working tool. For the full nine-month build track, the 2026 AI Roadmap for Indian engineering students maps what that path looks like from first-year foundations to final-year placement.

Primary sources

Frequently asked questions

How many coding problems are there in TCS NQT?

The Advanced section of TCS NQT includes one to two hands-on coding problems. Candidates appearing only for the Foundation section (Ninja track) do not face a live coding problem in the written test.

What languages can I use in TCS NQT coding section?

TCS NQT accepts C, C++, Java, and Python for the hands-on coding problem. You choose your preferred language at the start of that section. Most campus practice materials use C, but Python is equally accepted.

Is there negative marking in TCS NQT coding section?

There is no negative marking in the Foundation sections (Verbal, Reasoning, Numerical Ability). For the Advanced section, check the official TCS iON notification for your specific drive, as terms can vary.

What is the difficulty of TCS NQT coding questions?

TCS NQT coding problems sit at a LeetCode Easy to Medium difficulty range. They typically require one clean algorithm, standard input parsing, and correct edge-case handling. Complex data structures like trees or graphs are rare in the NQT coding section.

Can ECE and EEE students attempt TCS NQT coding section?

Yes. All engineering branches, including ECE, EEE, Mechanical, and Civil, can appear for TCS NQT. The coding section is language-agnostic — choose Python if you are more comfortable with it than C.

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