Tcs Coding Questions | 2021 Updated
2 questions with a shared time limit of 90 minutes, requiring knowledge of advanced data structures and algorithms. Allowed Languages: C, C++, Java, Python, and Perl. 2. Most Asked Coding Questions in 2021
Given a number N , write a program to obtain a number M by reversing the digits of N . If M contains trailing zeros, they must be removed (which happens naturally during integer reversal).
The 2021 programming assessments were split into two primary tiers based on the job role: (Systems Engineer) and Digital (High-differential package). TCS NQT (Ninja) Coding Section Number of Questions : 2 Questions Time Allotted : 45 Minutes (Total) Question 1 (Easy) : 15 Minutes Question 2 (Medium) : 30 Minutes Allowed Languages : C, C++, Java, Python, Perl TCS Digital Coding Section Number of Questions : 2 Questions Time Allotted : 60 Minutes (Total) Question 1 (Medium) : 25 Minutes Question 2 (Advanced) : 35 Minutes
Cracking the Code: Top TCS Coding Questions from 2021 Stepping into the TCS recruitment cycle—whether it's for
def candy_jar_system(): # Initial total capacity and minimum threshold total_candies = 10 min_threshold = 5 try: # Read input order order = int(input().strip()) except ValueError: print("INVALID INPUT") return # Validate the order if order <= 0 or order > total_candies: print("INVALID INPUT") print(f"NUMBER OF CANDIES AVAILABLE : total_candies") else: print(f"NUMBER OF CANDIES SOLD : order") remaining = total_candies - order # Check if refill is required if remaining <= min_threshold: remaining = total_candies print(f"NUMBER OF CANDIES AVAILABLE : remaining") if __name__ == "__main__": candy_jar_system() Use code with caution. Question 2: Oxygen Level Measurement Problem (Medium) Tcs Coding Questions 2021
If # occurs more than * , output a negative integer indicating the difference. If they occur equally, output 0 . Solution Approach
calculations on large array structures frequently triggered Time Limit Exceeded (TLE) errors. Using standard optimizations, such as prefix sums or hash maps, resolved these issues.
The behavior of static and extern variables across files.
import java.util.Scanner; public class Main public static void main(String[] args) Scanner sc = new Scanner(System.粉in); int[][] rounds = new int[3][3]; int[] average = new int[3]; for (int i = 0; i < 9; i++) if (sc.hasNextInt()) int maxAverage = 0; for (int i = 0; i < 3; i++) average[i] = rounds[i][0] / 3; if (average[i] > maxAverage) maxAverage = average[i]; if (maxAverage < 70) System.out.println("All trainees are unfit."); return; for (int i = 0; i < 3; i++) if (average[i] == maxAverage) System.out.println("Trainee Number : " + (i + 1)); Use code with caution. 4. Key Execution Pitfalls on TCS iON 2 questions with a shared time limit of
Reverse each individual row of the transposed matrix. Java Implementation
for char in S: # ASCII logic: 'a' is 97. Subtract 97 to get 0-25 range. # Add K, take modulo 26 to wrap around, add 97 back. new_char = chr(( (ord(char) - 97 + K) % 26) + 97) res += new_char
Solutions had to pass strict time-complexity limits (usually 1.0 second) and hidden test cases.
Accept a string and an integer K . Shift every character in the string K positions forward in the alphabet. (Assume the string contains only lowercase alphabets). If the shift goes past 'z', wrap around to 'a'. Most Asked Coding Questions in 2021 Given a
Find an index such that the sum of elements at lower indices equals the sum of elements at higher indices.
Test your code against empty inputs, negative numbers, or maximum constraints.
candies are available, sell them and print the number of candies sold and the remaining candies in the jar. is invalid (e.g., ), print "INVALID INPUT" and do not modify the jar count. Assume minimum threshold (Default capacity) (Refill threshold) Solution in Python 3
Arrays formed the backbone of the coding section. Common tasks included: (Most Asked) TCS NQT Coding Questions and Answers 2021