Tcs Coding Questions 2021 【QUICK Hacks】
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))
Q2 Solution: String reversal
Good luck. Your TCS career starts with a single System.out.println("Hello World"); — make it count. Keywords integrated: TCS Coding Questions 2021, TCS NQT, TCS Ninja coding, TCS Digital preparation, prime number problems, string manipulation TCS, coin change TCS. Tcs Coding Questions 2021
Input: "WWWNWWWNW" Output: "FNWFNW" (first three W→F, then single N, then next three W→F, then N, then single W).
Don't just read the solutions. Open your IDE right now, type them out, run test cases, break them, and fix them. That muscle memory will save you on exam day. def is_prime(n): if n < 2: return False
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.
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) Input: "WWWNWWWNW" Output: "FNWFNW" (first three W→F, then
#include <iostream> #include <string> using namespace std; int main() string s; cin >> s; string result = ""; int i = 0; while(i < s.length()) if(i+2 < s.length() && s[i]=='W' && s[i+1]=='W' && s[i+2]=='W') result += 'F'; i += 3; // skip ahead to avoid overlap else result += s[i]; i++;