Tcs Coding Questions 2021 May 2026

If you are searching for , 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.

This was a "modified greedy" problem that required recursion or DP. Question 5: "Binary String Operations" (Grouping Ones) Problem Statement: Given a binary string (e.g., "1001101"), you can perform operations: choose any contiguous substring containing exactly two '1's and flip all bits (0→1, 1→0). Find the minimum number of operations to make all bits '0'. Tcs Coding Questions 2021

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 , you are

M = 18. Standard greedy uses 10+5+3 = 3 coins. But 18-10=8, and 8 is not divisible by 3, so allowed. If M=20, standard: 10+10 =2 coins, but after first 10, remainder=10 (not divisible by 3) → allowed. If M=15, standard: 10+5=2 coins, but remainder after 10 is 5 (not div by 3) → allowed. Actually this twist made it tricky. Because TCS recycles logic

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];

Input: "WWWNWWWNW" Output: "FNWFNW" (first three W→F, then single N, then next three W→F, then N, then single W).

A teacher writes a sentence. She wants to reverse the words that have an even length, but leave odd-length words unchanged. Print the final sentence. Example: Input: "Hello World Python" → Output: "olleH World nohtyP"