Tcs Coding Questions 2021

Problem Statement: You are given an array of integers. Write a program to check if there are three consecutive even numbers or three consecutive odd numbers in the array. If found, print "True", otherwise print "False".

Input:

Output:

Example:

Input: 5 1 2 4 6 8 Output: True (Logic: 2, 4, 6 are three consecutive even numbers)

Solution (C++):

#include <iostream>
using namespace std;
int main() 
    int n;
    cin >> n;
    int arr[n];
for(int i = 0; i < n; i++) 
        cin >> arr[i];
int evenCount = 0, oddCount = 0;
    int flag = 0;
for(int i = 0; i < n; i++)  oddCount == 3) 
            flag = 1;
            break;
if(flag == 1) cout << "True";
    else cout << "False";
return 0;

Question 1 (15 marks):
Write a program to remove duplicate characters from a string without using an extra data structure (like set). Print the resulting string.
Test case: "programming""progamin" Tcs Coding Questions 2021

Question 2 (25 marks):
You are given an array of heights of students. Find the minimum number of jumps required to reach the end of the array, where you can jump from index i to i+1, i+2, or i+3, but you cannot land on an index where the height is greater than the current height.
This was the "killer" problem in TCS Digital December 2021.

In 2021, Tata Consultancy Services (TCS) continued its robust hiring through the TCS National Qualifier Test (NQT) and other off-campus/on-campus drives. The coding section remained a critical differentiator for securing an interview call. This write-up analyzes the nature, difficulty, topics, and sample problems from TCS coding questions asked in 2021.

If you are practicing these questions, avoid these pitfalls observed by TCS evaluators: Problem Statement: You are given an array of integers

Input: "aabbccdde" → Output: "abcde".
Concept: Two-pointer or stack.

Below are curated problems based on the actual difficulty level and logic asked in 2021.

Cookies make it easier for us to provide you with our services. With the usage of our services you permit us to use cookies.
More information Ok Decline