Tcs Coding Questions 2021 ((hot)) May 2026

TCS Coding Questions 2021: A Complete Breakdown for NQT and Digital Hiring

For thousands of engineering graduates in India, 2021 was a defining year for their careers. Tata Consultancy Services (TCS), one of the largest IT employers globally, conducted massive recruitment drives using the TCS National Qualifier Test (NQT) and the TCS Digital (Ninja) exams. If you are looking back at the pattern or preparing for future exams based on past trends, understanding the TCS coding questions from 2021 is arguably the most effective strategy.

Why 2021? Because that year marked a significant shift in difficulty and pattern. TCS moved away from purely textbook problems to more application-based logical coding, focusing heavily on arrays, strings, and efficient algorithms.

In this article, we will dissect the exact pattern, the most frequently asked questions, and provide solved examples of the top TCS coding questions from 2021.

Common Mistakes Students Made in 2021

If you are practicing these questions, avoid these pitfalls observed by TCS evaluators: Tcs Coding Questions 2021

  • Infinite Loops: Especially in while loops for base conversion (forgetting to update the divisor).
  • Ignoring Edge Cases: Input of size 1 for second largest element, negative numbers for binary conversion.
  • Over-engineering: TCS rewards working code, not the most efficient. Don't use dynamic programming when a simple sort works (unless sorting is banned in the problem).
  • Language Syntax: In C++, forgetting to include <bits/stdc++.h> or using gets() which is deprecated.

Marking Scheme (2021)

| Question Type | Marks | |---------------|-------| | Easy (array reversal, pattern) | 15–25 marks | | Medium (Kaprekar, anagrams) | 25–40 marks | | Partial (some test cases pass) | Proportional marks |

Important: TCS does not award marks for compilation errors or runtime exceptions.

Answer Key (Sample Outputs for Given Inputs)

  1. D@c#b$A
  2. 45
  3. 5 1 2 3 4
  4. 2
  5. 6
  6. 2


Practice Questions

TCS Coding Questions 2021: A Complete Analysis

Question 1: The Number Series (Based on Ascending/Descending Order)

Problem Statement: Write a program to sort the first half of an array in ascending order and the second half in descending order. TCS Coding Questions 2021: A Complete Breakdown for

  • Input: An integer N (size of the array), followed by N integers.
  • Output: The modified array.
  • Constraint: N is always even.

Example:

  • Input: 8, 2 4 1 5 8 3 6 9
  • Output: 1 2 4 5 9 8 6 3 (First 4 sorted ascending, next 4 sorted descending)

Solution Logic:

  1. Read the array.
  2. Sort the entire array in ascending order.
  3. Print the first half normally.
  4. Print the second half by iterating backwards.

Python Solution:

n = int(input())
arr = list(map(int, input().split()))
arr.sort()
mid = n // 2

2. Critical Constraints (Hidden Rules)

TCS coding questions often come with hidden constraints that are not explicitly stated in the problem text but are crucial for passing all test cases.

  1. Integer Size: Input numbers can be very large. If you use C++, use long long instead of int. In Java, use long or BigInteger. Python handles large integers automatically.
  2. Array Size: Arrays can have up to 100,000 elements. Ensure your algorithm is efficient (avoid nested loops if possible).
  3. Output Formatting: Strictly follow the output format. Extra spaces or newline characters (\n) can result in "Wrong Answer" verdicts.

Print first half (Ascending)

for i in range(mid): print(arr[i], end=" ")