Tcs Coding Questions 2021 Official
To master the "TCS Coding Questions 2021" pattern, follow this 3-week plan:
Based on student memory reports and discussion forums (like PrepInsta, GeeksforGeeks, Quora), the following topics dominated:
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. Tcs Coding Questions 2021
Wait—The actual TCS 2021 version was simpler: Replace all non-overlapping "WWW" with "F". But overlapping should remain.
Actual Pattern (Overlap not allowed):
Input: "WWWNWWWNW"
Output: "FNWFNW" (first three W→F, then single N, then next three W→F, then N, then single W). To master the "TCS Coding Questions 2021" pattern,
Solution (C++):
#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++; cout << result << endl; return 0;Key learning: Many lost marks by using replace()
Key learning: Many lost marks by using replace() in Python without controlling overlap.



