Tcs Coding | Questions 2021
Ready to create a quiz? Use Canvas to test your knowledge with a custom quiz Get started
In 2021, the TCS NQT (National Qualifier Test) featured a coding section primarily focused on fundamental algorithms, string manipulation, and array processing. For the 2021 hiring cycles (including the October 2020 and September 2021 slots), the coding round typically consisted of 1 to 2 questions with a time limit ranging from 30 to 45 minutes depending on the specific exam version (Ninja vs. Digital). TCS NQT Coding Sheet - TCS Coding Questions - Tutorial
The 2021 TCS coding rounds—specifically under the National Qualifier Test (NQT) and Digital drives—typically featured two coding questions that varied significantly in difficulty based on the candidate's target profile (Ninja or Digital). Exam Structure & Logistics (2021) Total Questions: 2 coding problems.
Time Duration: Typically 45 to 60 minutes for the coding section. Languages Allowed: C, C++, Java, Python 3.x, and Perl.
Platform: TCS iON or CodeVita platform, which are strict about input/output formats (no unnecessary "Enter value" prompts). Core Topics & Sample Questions
Questions in 2021 were often story-based, requiring candidates to parse lengthy descriptions to find the underlying algorithmic problem. 1. Array & String Manipulation
Move all Zeros to the End: Given an array, shift all zero elements to the end while maintaining the relative order of non-zero elements.
Equilibrium Index: Find an index such that the sum of elements at lower indices equals the sum of elements at higher indices.
Anagram Detection: Determine if two strings are anagrams of each other.
Longest Common Prefix: Find the longest common prefix string among an array of strings. 2. Number Theory & Logic
Sum of Digits (Single Digit Reduction): Repeatedly sum the digits of a number until a single digit is obtained (e.g., checking if the "digit sum" is 1). Tcs Coding Questions 2021
Series Completion: Finding the Nth term in mixed numeric series (e.g., a series that alternates between Fibonacci and Prime numbers).
Strong & Armstrong Numbers: Identifying if a number's digits meet specific mathematical criteria. 3. Advanced (Digital/Prime Profile)
Dynamic Programming: Problems like the 0/1 Knapsack or Longest Common Subsequence were common for higher-paying roles.
Graph Algorithms: Finding the shortest path in a weighted graph. Critical Solving Rules
To avoid disqualification or zero marks, candidates had to follow these strict I/O rules provided by Scribd:
No Prompt Text: Never print text like "The result is: ". Print only the result. Whitespace: Avoid leading or trailing spaces in the output.
Format: Floating-point numbers must match the specified precision exactly (e.g., %.2f for two decimal places).
Standard Streams: All input must come from STDIN and output must go to STDOUT. Technical MCQ Highlights (2021)
In addition to coding, students often faced technical MCQs focused on C fundamentals:
Pointers: Understanding int **ptr (pointer to a pointer) and address arithmetic. Ready to create a quiz
Memory Management: Functions like malloc(), calloc(), and free().
Storage Classes: The behavior of static and extern variables across files.
For further practice, you can explore the TCS NQT Coding Sheet on TakeUForward or simulated assessments on PrepInsta. 3 Real TCS Coding Questions You Must Practice (NQT)
1. Reverse with special chars
- Two-pointer: left=0, right=n-1.
- If both are letters → swap, move both.
- If left not letter → left++; if right not letter → right--.
5. The "Matrix Spiral Traversal" (TCS Digital Classic)
Asked in: TCS Digital (Multiple slots – November 2021)
Problem Statement:
Given an m x n matrix, print all elements in spiral order starting from the top-left corner moving right, then down, then left, then up.
Example:
Input:
1 2 3 4
5 6 7 8
9 10 11 12
Output: 1 2 3 4 8 12 11 10 9 5 6 7
Approach (Logic): Manage four boundaries: top, bottom, left, right. Loop while top <= bottom and left <= right.
9. Compute sum of digits until single digit (digital root)
Input: 9875 → 9+8+7+5=29 → 2+9=11 → 1+1=2.
Concept: Recursion or formula 1 + (num-1)%9.
Part 4: How to Practice TCS Coding Questions Effectively
Random practice won't help. Follow this 3-week plan:
Week 1: Brush up basics
- Solve 50 problems on CodeChef (Easy tag) and HackerRank (30 days of code).
- Focus on: prime sieve, digit extraction, pattern printing.
Week 2: TCS-specific platforms
- Use PrepInsta's TCS NQT coding playlist (free).
- Solve all 2021 questions from GeeksforGeeks "TCS Coding Practice" section.
Week 3: Mock tests
- Take iON mock tests (TCS official) – they simulate the exact environment.
- Practice typing code without IDE autocomplete (crucial!)
3. The "String Palindrome with One Skip"
Asked in: TCS NQT Advanced (July 2021)
Problem Statement:
Given a string, determine if it can be a palindrome by removing at most one character. Print "Yes" if possible, else "No". This is a variation of LeetCode 680 (Valid Palindrome II).
Example:
- Input:
"abca" - Output:
Yes(Remove 'b' or 'c' -> "aca" or "aba")
Approach (Java):
public class Main public static boolean validPalindrome(String s) int left = 0, right = s.length() - 1; while (left < right) if (s.charAt(left) != s.charAt(right)) left++; right--; return true;private static boolean isPalindrome(String s, int left, int right) while (left < right) if (s.charAt(left) != s.charAt(right)) return false; left++; right--; return true; public static void main(String[] args) String str = "abca"; System.out.println(validPalindrome(str) ? "Yes" : "No");
4. String manipulation – toggle case
Input: "tCS Is eAsY" → Output: "Tcs iS EaSy".
Concept: Iterate, flip case using ASCII manipulation.
4. Important Topics to Prepare
TCS 2021 questions largely focused on these algorithms. Master these patterns, and you can solve almost any variation: Two-pointer: left=0, right=n-1
- Number Series: Fibonacci, GCD, Factorial, finding if a number is part of a specific series (e.g., 3, 8, 15, 24...).
- String Manipulation: Removing vowels, converting case, counting specific characters, checking palindromes.
- 1D Arrays: Finding the maximum/minimum, sorting, reversing arrays.
- Date/Time Logic: Calculating the number of days between two dates or finding the day of the week (rare but asked).
- Number System: Decimal to Binary conversion, Prime checks, Armstrong numbers.