Problem Statement: Consider the following
For those preparing for TCS recruitment, the 2021 coding assessments (NQT, Ninja, and Digital) centered on core programming logic, array manipulations, and mathematical series. Succeeding in these rounds requires a strong grasp of standard input/output (STDIN/STDOUT) and basic data structures GitHub Pages documentation Core Coding Topics from 2021
The following topics were highly frequent across different shifts in 2021: Array Operations
: Finding the second largest/smallest element, rotating an array by positions, and finding missing numbers in a sequence. String Manipulation
: Palindrome checks, counting vowels and consonants, and anagram detection. Number Theory
: Prime number checks, GCD/LCM calculation, Armstrong numbers, and Fibonacci series generation. Mathematical Series : Identifying the cap N raised to the t h power term in complex geometric or mixed numeric series. Highly Asked Questions (2021 Samples)
Based on papers from 2021, here are specific problems frequently encountered by candidates: Question Type Problem Description Basic Logic The Candies Problem : Given a fixed number of candies ( ) and a threshold ( ), take user input
is within range, print candies sold and left; otherwise, print "INVALID INPUT". Parking Lot Index : Given an
matrix of 0s (empty) and 1s (full), find the row index with the maximum number of 1s. Mixed Series cap N raised to the t h power : Find the cap N raised to the t h power term of a series like (often a combination of two different geometric series). Trainee Oxygen Levels
: Input oxygen levels for 3 trainees over 3 rounds. Calculate their average and identify the trainee with the highest average, provided it's above a minimum threshold. Preparation Resources
To practice these specific 2021 patterns, you can explore specialized coding sheets and repositories: Coding Sheets : Comprehensive lists of top 100 questions are available on Frontlines Media takeUforward Practice Platforms : Detailed solutions for NQT 2021 problems can be found on Advanced Topics : For Digital or Prime roles, focus on Dynamic Programming (e.g., 0/1 Knapsack) and Graph Theory (e.g., Shortest Path). TCS NQT 2021 Test - GitHub Pages
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).
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. Tcs Coding Questions 2021
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.
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)
Here are some TCS coding questions from 2021, along with a useful piece of code for each:
1. Find the first non-repeating character in a string
Given a string, find the first non-repeating character in it.
Example: Input - "aabbc", Output - "c"
def first_non_repeating_char(s):
char_count = {}
for char in s:
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
for char in s:
if char_count[char] == 1:
return char
return None
print(first_non_repeating_char("aabbc")) # Output: "c"
2. Check if a string is a palindrome
Given a string, check if it's a palindrome or not.
Example: Input - "madam", Output - True
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("madam")) # Output: True
3. Find the maximum sum of a subarray
Given an array of integers, find the maximum sum of a subarray.
Example: Input - [-2, 1, -3, 4, -1, 2, 1, -5, 4], Output - 6
def max_subarray_sum(arr):
max_sum = float('-inf')
current_sum = 0
for num in arr:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
print(max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4])) # Output: 6
4. Count the number of pairs with a given sum
Given an array of integers and a target sum, count the number of pairs with that sum. Concept: Counter variable inside nested loops.
Example: Input - [1, 2, 3, 4, 5], target sum - 7, Output - 2
def count_pairs_with_sum(arr, target_sum):
count = 0
seen = set()
for num in arr:
complement = target_sum - num
if complement in seen:
count += 1
seen.add(num)
return count
print(count_pairs_with_sum([1, 2, 3, 4, 5], 7)) # Output: 2
5. Find the middle element of a linked list
Given a linked list, find the middle element.
Example: Input - 1 -> 2 -> 3 -> 4 -> 5, Output - 3
class Node:
def __init__(self, data):
self.data = data
self.next = None
def find_middle_element(head):
slow = head
fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow.data
# Create a sample linked list: 1 -> 2 -> 3 -> 4 -> 5
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
head.next.next.next = Node(4)
head.next.next.next.next = Node(5)
print(find_middle_element(head)) # Output: 3
Analysis of TCS NQT Coding Questions (2021) The 2021 TCS National Qualifier Test (NQT) coding section was characterized by a shift toward assessing fundamental problem-solving efficiency and precision in handling standard input/output. The questions generally ranged from easy to moderate difficulty, focusing heavily on mathematical series, string manipulation, and array-based logic. 1. Exam Structure and Pattern
The 2021 NQT coding section typically followed a two-question format within the advanced section of a 190-minute total examination. Candidates were often given one simple question (approx. 15-20 minutes) and one more complex algorithmic question (approx. 30 minutes). Supported Languages: C, C++, Java, Python 2.7, and Perl. Evaluation: Based on both public and private test cases.
Key Requirement: Strict adherence to output formats, including no leading/trailing spaces and specific precision for floating-point numbers. 2. Frequently Recurring Question Themes
Based on 2021 slot analyses, questions were primarily drawn from these core areas:
In 2021, TCS National Qualifier Test (NQT) coding questions typically focused on fundamental programming logic, string manipulation, and mathematical series. Candidates were generally required to solve 1–2 coding questions within a shared time limit of 30–45 minutes. Core Topics and Question Types
According to resources like the TCS NQT Coding Sheet, the 2021 exams frequently included:
This report summarizes the coding questions and exam pattern for the 2021 TCS National Qualifier Test (NQT). The 2021 recruitment cycle introduced several specific problem types focused on basic data structures and real-world scenario modeling. 1. Exam Overview (2021 Cycle)
The 2021 TCS NQT followed a structured format where the coding section was pivotal for both "Ninja" and "Digital" hiring profiles. Number of Questions: 2.
Time Allotted: Approximately 45 to 90 minutes, depending on the specific slot and hiring category. Permitted Languages: C, C++, Java, Python, and Perl. Platform: TCS iON or CodeVita platform. 2. Core Coding Topics
Analysis of 2021 slots shows that questions primarily tested foundational logic rather than advanced competitive programming: TCS NQT Most Repeated Coding Questions | PDF - Scribd
In 2021, the TCS National Qualifier Test (NQT) and Digital Capability Assessment (DCA) featured a shift toward mixed-series logic and practical scenario-based problems. While the "Ninja" role prioritized basic mathematical logic, "Digital" roles required handling complex data structures like matrices and linked lists. 1. Top-Asked Coding Questions (2021 Recap)
Difference between Even and Odd Position Sums: Given a number (up to 100 digits), find the difference between the sum of digits at odd and even positions. Jar of Candies: A JAR has a capacity . Given an order for candies, update the JAR count. If
is greater than available, return "INVALID INPUT." When candies fall below a threshold , the jar is refilled.
Base 17 to Base 10 Conversion: Interpret a base-17 number (where ) and convert it to its decimal equivalent. Mixed Series Term Finder: Identify the
-th term in hybrid series, such as a mix of natural numbers and their doubles ( ) or geometric progressions.
Seating Inefficiency: Calculate the "total inefficiency" based on how people are seated at tables and the resulting arguments, often involving conditional logic or optimization. 2. Core Patterns & Focus Areas Key Topics Example Logic Arrays Rotation, Equilibrium index, Sorting 0s/1s/2s Finding the second largest without full sorting. Strings Palindromes, Anagrams, Frequency counts Finding the most repeating character in a word. Numbers Prime ranges, Armstrong numbers, GCD/LCM Checking if a number is a "Strong" or "Harshad" number. Digital/Prime Dynamic Programming, Matrix rotation, Graphs Rotating a matrix 90 degrees or solving the 0/1 Knapsack. 3. Preparation Resources
Practice Sheets: Comprehensive lists of previously asked questions are available on TakeUForward and PrepInsta.
Platform-Specific Practice: Solve real-world TCS problems on CodeChef's TCS NQT Practice. right = s.length() - 1
Visual Learning: Detailed walkthroughs of 2021 slot-specific questions can be found on YouTube channels like Placement Phodenge and Technoname.
Pro-Tip: The TCS iON compiler is notoriously strict regarding standard input/output; ensure your code doesn't print extra "Enter number" prompts, as this can cause test cases to fail.
Master the TCS NQT 2021 Coding Round: Most Frequently Asked Questions & Solutions Getting into Tata Consultancy Services (TCS)
often starts with the National Qualifier Test (NQT). The 2021 coding round was a major milestone for thousands of freshers, and its questions still serve as the gold standard for preparation today. Whether you are aiming for the profile, mastering these patterns is essential. The 2021 Exam Pattern at a Glance In 2021, the TCS NQT coding section typically featured two questions of varying difficulty: Question 1 (Easy/Foundation):
Focused on basic logic, such as mathematical formulas or basic array manipulation. You usually had 15–20 minutes to solve it. Question 2 (Medium/Advanced):
Involved story-based problems, complex data structures, or optimization techniques like Dynamic Programming. Time allotted was generally 30–45 minutes. Top 5 TCS Coding Questions from 2021
1. Find the Smallest Number Whose Product of Digits Equals N This was a frequent star in the Digital assessment. The Problem: Given a positive integer , find the smallest number such that the product of its digits is exactly → Output: , and 25 is smaller than 52). Key Logic:
Work backwards by dividing the number by digits from 9 down to 2 and store them in an array to form the smallest value. 2. The "UNO" Number Challenge A popular question from the September 2021 slots. The Problem: Given a positive integer
, continuously sum its digits until a single-digit value is obtained. Determine if that final digit is . Result: UNO. 3. Base 17 Conversion The Problem:
TCS often tests base conversions. In 2021, a specific challenge involved converting a number from (using A=10, B=11... G=16) to decimal (Base 10). → Output: 4. Cyclically Rotate an Array The Problem: Given an array of integers and a value , rotate the array clockwise by positions. [10, 20, 30, 40, 50] → Output: [40, 50, 10, 20, 30] Use the formula (index + K) % N
to find the new position or use array slicing in Python for a one-liner solution. 5. Series Completion (Fibonacci & Prime Mixed) The Problem:
Generate a series where even positions are the Fibonacci sequence and odd positions are Prime numbers. Series Example: n raised to the t h power term of this mixed series. Quick Tips for Success
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:
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");
Input: "tCS Is eAsY" → Output: "Tcs iS EaSy".
Concept: Iterate, flip case using ASCII manipulation.
Example N=4:
1
2 3
4 5 6
7 8 9 10
Concept: Counter variable inside nested loops.