Tcs Coding Questions 2021 < No Sign-up >

cout << result << endl; return 0;

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

Wait—The actual TCS 2021 version was simpler: Replace all non-overlapping "WWW" with "F". But overlapping should remain. Tcs Coding Questions 2021

denoms = [50, 25, 10, 5, 3, 1] def min_coins(M, idx=0): if M == 0: return 0 for i in range(idx, len(denoms)): coin = denoms[i] if coin <= M: if coin == 10 and (M - coin) % 3 == 0: continue # skip 10 if remainder divisible by 3 res = min_coins(M - coin, i) if res != -1: return 1 + res return -1 M = int(input()) print(min_coins(M))

def sieve(n): is_prime = [True]*(n+1) is_prime[0]=is_prime[1]=False for i in range(2,int(n**0.5)+1): if is_prime[i]: for j in range(i*i, n+1, i): is_prime[j]=False return is_prime L, R = map(int, input().split()) prime_flags = sieve(R) total = sum(i for i in range(L, R+1) if prime_flags[i]) print(total) cout &lt;&lt; result &lt;&lt; endl; return 0; import java

Tests nested function calls and primality checking within constraints (n ≤ 10^6). Question 2: "Cricket Fever" – Overlapping Bowlers (String & List) Problem Statement: In a cricket match, the captain maintains a string of 'W' (wicket) and 'N' (normal ball). A bowler is said to have "fever" if he takes 3 consecutive wickets (i.e., "WWW"). Given a string, replace every such occurrence of "WWW" with "F" (fever) and print the modified string. However, if two fever patterns overlap (like "WWWW" -> contains two overlapping "WWW" starting at index 0 and 1), count it only once.

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. Question 2: "Cricket Fever" – Overlapping Bowlers (String

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();