Coding Questions 2021 Fixed | Tcs
Master the Code: A Complete Guide to TCS Coding Questions 2021 (Patterns, Solutions & Tips)
Introduction: The Gatekeeper of an IT Dream
For millions of engineering graduates in India, Tata Consultancy Services (TCS) represents more than just a job—it is a career launchpad. As the largest private-sector employer in the country, TCS conducts its National Qualifier Test (NQT) yearly. While the exam pattern evolves, the coding section remains the highest-scoring and most decisive part.
If you are searching for TCS Coding Questions 2021, you are likely preparing for the TCS NQT (National Qualifier Test) or the TCS Ninja/Digital hiring rounds. Although 2021 was a few years ago, those questions remain a goldmine of practice. Why? Because TCS recycles logic. The syntax of the language may change, but the algorithmic patterns—arrays, strings, greedy algorithms, and mathematical puzzles—remain timeless.
In this article, we will dissect the TCS Coding Questions from 2021, categorize them by difficulty, provide step-by-step solutions, and share strategies to crack the automatic evaluator.
Conclusion
The TCS coding questions from 2021 represent a sweet spot in the company’s hiring history—modern enough to test logic, yet classic enough to be predictable. By focusing on array manipulation, two-pointer techniques, recursion, and edge-case handling, you can easily score 85%+ in the coding section.
Do not just memorize the code. Understand the why behind the logic. TCS is looking for engineers who can debug and adapt. Take the six questions listed above, write them from scratch three times each, and you will be more prepared than 90% of candidates who sat for the 2021 exam.
Further Resources:
- Watch: "TCS NQT Coding Questions 2021 – Live Solution" on YouTube (by PrepInsta).
- Practice: TCS 2021 playlist on CodeChef and HackerRank.
- Download: The unofficial 2021 TCS Coding Question Bank (PDF available on Telegram groups).
Good luck with your TCS preparation!
Cracking the Code: Top TCS Coding Questions from 2021 Stepping into the TCS recruitment cycle—whether it's for Tcs Coding Questions 2021
roles—often feels like a high-stakes puzzle. In 2021, the coding questions shifted toward story-based problems that test logic just as much as syntax.
If you're preparing for upcoming drives, revisiting these real-world problems from 2021 is the best way to master the pattern. 1. The Candy Jar Problem (TCS NQT 2021)
This classic condition-based question appeared in multiple 2021 slots. It tests your ability to handle basic input-output and constraints. Problem Statement: A jar has a capacity At any point, it has If a customer orders candies, you must update the jar. Refill Rule:
The jar is refilled to full only when the number of remaining candies drops to or below a threshold Number of candies ordered. Number of candies sold and remaining. If the order exceeds INVALID INPUT Step-by-Step Logic: Initialize Constants and the refill threshold Validate Input : Check if the order is between Calculate Remaining : Subtract the order from Refill Check : If the new 2. Two-Wheeler vs. Four-Wheeler (TCS Ninja 2021)
This problem is a favorite for testing mathematical logic through code. Problem Statement:
An automobile company produces Two-Wheelers (TW) and Four-Wheelers (FW). You are given: : Total number of vehicles. : Total number of wheels. Find the count of TW and FW. Mathematical Solution: x plus y equals cap V 2 x plus 4 y equals cap W Solving these equations: Constraint Check: is odd, or INVALID INPUT 3. Digit Sum Difference (TCS Digital 2021)
High-level "Digital" roles often feature string manipulation or number theory. Problem Statement:
Given a number (up to 100 digits), find the absolute difference between the sum of digits at odd positions and even positions. Key Strategy: Handle Large Input : Since the number can have 100 digits, read it as a Master the Code: A Complete Guide to TCS
: Use a loop to traverse the string, converting each character to its integer value and adding it to the respective based on the index. 4. Even Product Pairs (TCS Digital Sept 2021)
This story-based problem focused on combinatorics and basic parity. Problem Statement: A man has two bags: Bag A with coins and Bag B with
coins. Find the number of ways to pick one coin from each such that their product is an even number Quick Logic: A product is even if at least one of the numbers is even. Total Ways
Total Ways equals open paren Even sub cap A cross Even sub cap B close paren plus open paren Even sub cap A cross Odd sub cap B close paren plus open paren Odd sub cap A cross Even sub cap B close paren Alternatively: Total Ways
Total Ways equals open paren cap N cross cap M close paren minus open paren Odd sub cap A cross Odd sub cap B close paren Pro-Tips for the TCS Coding Round (Most Asked) TCS NQT Coding Questions and Answers 2021
Topic-wise Analysis (2021 Trends)
The questions in 2021 largely focused on:
- Number Series: Finding the next term or printing a specific series pattern.
- Number Systems: Armstrong numbers, Palindromes, Prime factors.
- String Manipulation: Removing vowels, reversing strings, toggling cases.
- General Logic: Discount calculations, Fare calculations, BMI logic.
Question 1: The "Prime Ministers" Problem (Array & Digit Sum)
Problem Statement:
An international organization defines a "Prime Minister" number as a positive integer greater than 10 that satisfies two conditions:
- The number itself is prime.
- The sum of its digits is also prime.
Given an array of integers, print the count of such "Prime Minister" numbers. Conclusion The TCS coding questions from 2021 represent
Example:
Input: [11, 23, 41, 29, 56]
Output: 3 (Because 11→1+1=2(prime), 23→2+3=5(prime), 41→4+1=5(prime), 29 is prime but 2+9=11(prime) actually also qualifies—so 4? Wait: 56 is not prime. So output is 4).
Solution (Python):
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 Truedef digit_sum(n): return sum(int(d) for d in str(n))
arr = list(map(int, input().split())) count = 0 for num in arr: if num > 10 and is_prime(num) and is_prime(digit_sum(num)): count += 1 print(count)
Why this was asked in 2021: Tests nested function calls and primality checking within constraints (n ≤ 10^6).
Exam Pattern Overview
- Number of Questions: 2
- Time Allotted: 45 Minutes
- Difficulty: Question 1 (Easy/Medium), Question 2 (Medium/Hard).
- Languages Allowed: C, C++, Java, Python, Perl, C#.
The 2021 Exam Pattern (Coding Section)
Before diving into the questions, let's revisit the structure. The TCS NQT 2021 had two mandatory rounds where coding was tested:
- Foundation Level (Ninja): Easier, focusing on loops, conditionals, and basic data structures.
- Advanced Level (Digital): Harder, requiring knowledge of dynamic programming, recursion, and data structure optimization.
Key Constraints (Typical for 2021):
- Languages allowed: C, C++, Java, Python, Perl, Ruby.
- Number of Questions: 2 to 3 coding problems (1 compulsory + 1-2 optional advanced).
- Time allocated: 15–20 minutes per coding problem.
- Difficulty: Easy to Medium (with one "twist").
Most students reported that solving the previous year’s questions (2021) guaranteed at least a 50% score in the coding section.












