Tcs Coding Questions 2021 -

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.

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

Wait—The actual TCS 2021 version was simpler: Replace all non-overlapping "WWW" with "F". But overlapping should remain. Write a program to find the sum of

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. Standard greedy: 10+3 = 2 coins

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

cout << result << endl; return 0;