Tcs Coding Questions 2021 May 2026

After analyzing 50+ student reports, here are the recurring themes:


In the TCS NQT (Ninja and Digital roles), the coding section has specific constraints you must know before writing a single line of code.

  • Input/Output: You must read input from stdin (Standard Input) and print output to stdout (Standard Output). Do not write input prompts (e.g., don't print "Enter a number:").
  • Languages Allowed: C, C++, Java, Python, Perl, C#.
  • Problem Statement: Write a program to remove all vowels from a given string.

    Example:

    Solution Logic: Iterate through the string. If a character is present in the set of vowels, skip it; otherwise, add it to the result.

    C Solution:

    #include <stdio.h>
    #include <string.h>
    

    int main() char str[100]; scanf("%[^\n]s", str); // Read string with spaces

    for(int i = 0; str[i] != '\0'; i++) 
    return 0;
    


    Problem Statement:
    An international organization defines a "Prime Minister" number as a positive integer greater than 10 that satisfies two conditions:

    Given an array of integers, print the count of such "Prime Minister" numbers.

    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 True
    

    def 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). Tcs Coding Questions 2021


    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 After analyzing 50+ student reports, here are the

    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


    Here are the most frequently asked patterns, reconstructed from student memory and forums like PrepInsta, GeeksforGeeks, and CodeChef discussions.

    Problem Statement:
    An autobiographical number is an integer N such that the first digit (from left) counts how many zeros are in N, the second digit counts how many ones, and so on. Given a number (as a string), verify if it's autobiographical.

    Example:
    1210 → 1 zero, 2 ones, 1 two, 0 threes → Yes.
    2020 → 2 zeros, 0 ones, 2 twos, 0 threes → Yes? Wait, check: In 2020, digits: 2,0,2,0.

    Solution (Java):

    import java.util.Scanner;
    

    public class Main public static void main(String[] args) Scanner sc = new Scanner(System.in); String num = sc.next(); int len = num.length(); int[] freq = new int[10];

        for (char ch : num.toCharArray()) 
            freq[ch - '0']++;
    boolean auto = true;
        for (int i = 0; i < len; i++) 
            int digit = num.charAt(i) - '0';
            if (freq[i] != digit) 
                auto = false;
                break;
    System.out.println(auto ? "Autobiographical" : "Not");
        sc.close();
    

    2021 trend: TCS loved problems that mix string indexing and array frequency.