Tcs Coding Questions 2021 Review
Write a program to find the sum of all prime numbers between two given integers L and R (inclusive). Constraints: 1 ≤ L ≤ R ≤ 10^6.
Input: "WWWNWWWNW" Output: "FNWFNW" (first three W→F, then single N, then next three W→F, then N, then single W). Tcs Coding Questions 2021
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'. Write a program to find the sum of
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. This was a "modified greedy" problem that required
M=13. Standard greedy: 10+3 = 2 coins. But remainder after 10 =3 (divisible by 3) → forbidden. So you must choose 5+5+3 =3 coins.
"1001" → Choose substring indices 1 to 3 ("001")? Actually original: 1 0 0 1. Pick substring positions 2-4 (0,0,1) has only one '1'. Not allowed. This was so tricky that TCS 2021 actually had a simpler version: Count the number of groups of consecutive '1's.
s = input().split() res = [] for word in s: if len(word) % 2 == 0: res.append(word[::-1]) else: res.append(word) print(' '.join(res)) TCS does not invent entirely new problems every year. The TCS Coding Questions 2021 set is a blueprint. The prime-checking logic, the string group counting, the coin problem with a twist—these concepts reappear in 2023, 2024, and will continue.
