Tcs Coding Questions 2021 May 2026
for i in range(n-1, mid-1, -1): print(arr[i], end=" ")
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++)
if(arr[i] % 2 == 0)
evenCount++;
oddCount = 0;
else
oddCount++;
evenCount = 0;
if(evenCount == 3
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"
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. Tcs Coding Questions 2021