Published: 12 Nov 2025 | Reading Time: 5 min
If you are preparing for the TCS digital coding assessment, here's the truth:
You don't need to memorize hundreds of programs. You need to understand the logic behind the most common coding patterns that appear every year.
TCS tests how you think. Not how many programs you have seen.
Most candidates struggle not because the questions are challenging but because they aren't used to the type of coding questions they will be asked. Once you know the types of arrays, strings, sorting, and mathematical logic involved, the questions become predictable and easy to answer.
This guide brings you the exact coding questions, broken down with solutions, explanations, and optimized code so you can practice smarter and crack the coding round with confidence.
TCS Digital is a recruitment drive especially designed to attract tech-savvy graduates and graduates with a technical background. The program tests graduates with a typical stage, an aptitude test, a technical interview, and a coding round. In each of these stages, a candidate's success often hinges on their ability to solve complex problems quickly and effectively under time constraints. Therefore, it is crucial that applicants feel comfortable coding for the TCS digital application.
Understanding the structure and rules of the TCS Digital coding round is essential for effective preparation. Below are the key details about the syllabus, exam pattern, allowed languages, and marking scheme for the coding assessment.
The types of coding problems in TCS Digital cover the following topics:
Candidates can choose from a wide range of programming languages, including:
This flexibility allows you to code in the language you are most comfortable with.
Similar to other coding rounds, the TCS Digital coding section consists of a variety of questions to test your logical thinking, programming ability, and coding. Understanding the common categories and patterns can help you to prepare more fully. Below are some of the main forms of questions you may encounter.
It is common for questions to involve arrays or lists. For example, you may be asked to:
Questions focused on strings are designed to test your ability to process and analyze text data. Examples include:
Questions in this category test your ability to apply mathematical logic, such as:
Questions on linked lists assess your understanding of dynamic data types. You may be asked to:
Questions based on trees can include:
You may see questions that require printing certain patterns using loops, such as:
Some questions test your ability to reason and work through scenarios, or edge cases.
Classic searching (linear, binary) and sorting (bubble, merge, quick) algorithms often form the basis of coding questions, either directly or as part of a larger problem.
One of the best ways to practice for the TCS Digital coding assessment is to work through actual coding questions. Here are some sample coding questions that mimic the format, level of difficulty, and topics that you may encounter on the exam. Each question includes a clear problem statement, the input/output format, and a thorough solution in multiple programming languages.
Problem Statement:
Given an array Arr[] of N integers and a positive integer K, cyclically rotate the array clockwise by K.
Input Format:
Output Format:
Example:
Input
5
10 20 30 40 50
2
Output
40 50 10 20 30
#include <iostream>
#include <vector>
using namespace std;
vector<int> rotate(int nums[], int n, int k) {
k = k % n;
vector<int> ans(n);
for (int i = 0; i < k; i++) {
ans[i] = nums[n - k + i];
}
int index = 0;
for (int i = k; i < n; i++) {
ans[i] = nums[index++];
}
return ans;
}
int main() {
int N, K;
cin >> N;
int Array[N];
for (int i = 0; i < N; ++i) {
cin >> Array[i];
}
cin >> K;
vector<int> ans = rotate(Array, N, K);
for (int i = 0; i < N; ++i) {
cout << ans[i] << ' ';
}
}
import java.util.Scanner;
public class RotateArray {
public static int[] rotate(int[] nums, int k) {
int n = nums.length;
k = k % n;
int[] ans = new int[n];
for (int i = 0; i < k; i++) {
ans[i] = nums[n - k + i];
}
for (int i = k; i < n; i++) {
ans[i] = nums[i - k];
}
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
int k = scanner.nextInt();
int[] rotated = rotate(arr, k);
for (int num : rotated) {
System.out.print(num + " ");
}
scanner.close();
}
}
def rotate(arr, k):
n = len(arr)
k = k % n
return arr[-k:] + arr[:-k]
N = int(input())
arr = list(map(int, input().split()))
K = int(input())
rotated = rotate(arr, K)
print(' '.join(map(str, rotated)))
Problem Statement:
Given two non-negative integers n1 and n2, count how many numbers in the range [n1, n2] do not have repeated digits.
Input Format:
Output Format:
Example:
Input
11
15
Output
4
#include <iostream>
#include <vector>
using namespace std;
bool hasRepeatedDigits(int num) {
vector<bool> visited(10, false);
while (num > 0) {
int digit = num % 10;
if (visited[digit]) return false;
visited[digit] = true;
num /= 10;
}
return true;
}
int countUniqueDigits(int n1, int n2) {
int count = 0;
for (int i = n1; i <= n2; i++) {
if (hasRepeatedDigits(i)) count++;
}
return count;
}
int main() {
int n1, n2;
cin >> n1 >> n2;
cout << countUniqueDigits(n1, n2);
}
import java.util.Scanner;
public class UniqueDigits {
public static boolean hasRepeatedDigits(int num) {
boolean[] visited = new boolean[10];
while (num > 0) {
int digit = num % 10;
if (visited[digit]) return false;
visited[digit] = true;
num /= 10;
}
return true;
}
public static int countUniqueDigits(int n1, int n2) {
int count = 0;
for (int i = n1; i <= n2; i++) {
if (hasRepeatedDigits(i)) count++;
}
return count;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n1 = scanner.nextInt();
int n2 = scanner.nextInt();
System.out.println(countUniqueDigits(n1, n2));
scanner.close();
}
}
def has_repeated_digits(num):
visited = [False] * 10
while num > 0:
digit = num % 10
if visited[digit]:
return False
visited[digit] = True
num //= 10
return True
def count_unique_digits(n1, n2):
count = 0
for i in range(n1, n2 + 1):
if has_repeated_digits(i):
count += 1
return count
n1, n2 = map(int, input().split())
print(count_unique_digits(n1, n2))
Problem Statement:
Given a string, split it into exactly 3 palindromic substrings. If it's not possible, print "Impossible".
Input Format:
Output Format:
Example:
Input
nayannamantenet
Output
nayan
naman
tenet
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(const string& s) {
return s == string(s.rbegin(), s.rend());
}
void findPalindromes(const string& str) {
int len = str.length();
for (int i = 1; i < len - 1; i++) {
string str1 = str.substr(0, i);
if (isPalindrome(str1)) {
for (int j = 1; j < len - i; j++) {
string str2 = str.substr(i, j);
string str3 = str.substr(i + j);
if (isPalindrome(str2) && isPalindrome(str3)) {
cout << str1 << "\n" << str2 << "\n" << str3 << endl;
return;
}
}
}
}
cout << "Impossible" << endl;
}
int main() {
string str;
cin >> str;
findPalindromes(str);
}
import java.util.Scanner;
public class PalindromeSplit {
public static boolean isPalindrome(String s) {
return s.equals(new StringBuilder(s).reverse().toString());
}
public static void findPalindromes(String str) {
int len = str.length();
for (int i = 1; i < len - 1; i++) {
String str1 = str.substring(0, i);
if (isPalindrome(str1)) {
for (int j = 1; j < len - i; j++) {
String str2 = str.substring(i, i + j);
String str3 = str.substring(i + j);
if (isPalindrome(str2) && isPalindrome(str3)) {
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
return;
}
}
}
}
System.out.println("Impossible");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
findPalindromes(str);
scanner.close();
}
}
def is_palindrome(s):
return s == s[::-1]
def find_palindromes(s):
length = len(s)
for i in range(1, length - 1):
str1 = s[:i]
if is_palindrome(str1):
for j in range(1, length - i):
str2 = s[i:i+j]
str3 = s[i+j:]
if is_palindrome(str2) and is_palindrome(str3):
print(str1)
print(str2)
print(str3)
return
print("Impossible")
s = input()
find_palindromes(s)
Problem Statement:
Given a range [low, high], select K numbers from the range (numbers can repeat) such that their sum is even. Output the number of such permutations modulo 1e9+7.
Input Format:
Output Format:
Example:
Input
4 5
3
Output
4
#include <iostream>
using namespace std;
#define mod 1000000007
long long countPermutations(long long low, long long high, long long k) {
long long even = (high / 2) - ((low - 1) / 2);
long long odd = (high - low + 1) - even;
long long evenCount = 1;
long long oddCount = 1;
for (long long i = 0; i < k; i++) {
if (i % 2 == 0) {
evenCount = (evenCount * even) % mod;
} else {
oddCount = (oddCount * odd) % mod;
}
}
return (evenCount + oddCount) % mod;
}
int main() {
long long low, high, k;
cin >> low >> high >> k;
cout << countPermutations(low, high, k);
}
import java.util.Scanner;
public class CountEvenPermutations {
static final int MOD = 1000000007;
public static long countPermutations(long low, long high, long k) {
long even = (high / 2) - ((low - 1) / 2);
long odd = (high - low + 1) - even;
long evenCount = 1;
long oddCount = 1;
for (long i = 0; i < k; i++) {
if (i % 2 == 0) {
evenCount = (evenCount * even) % MOD;
} else {
oddCount = (oddCount * odd) % MOD;
}
}
return (evenCount + oddCount) % MOD;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long low = scanner.nextLong();
long high = scanner.nextLong();
long k = scanner.nextLong();
System.out.println(countPermutations(low, high, k));
scanner.close();
}
}
def count_permutations(low, high, k):
mod = 1000000007
even = (high // 2) - ((low - 1) // 2)
odd = (high - low + 1) - even
even_count = 1
odd_count = 1
for i in range(k):
if i % 2 == 0:
even_count = (even_count * even) % mod
else:
odd_count = (odd_count * odd) % mod
return (even_count + odd_count) % mod
low, high, k = map(int, input().split())
print(count_permutations(low, high, k))
Problem Statement:
Given a string, find the first non-repeating character.
Input Format:
Output Format:
Example:
Input
ccbp
Output
b
#include <iostream>
#include <unordered_map>
using namespace std;
char firstUniqueChar(const string& str) {
unordered_map<char, int> charCount;
for (char ch : str) {
charCount[ch]++;
}
for (char ch : str) {
if (charCount[ch] == 1) {
return ch;
}
}
return '-';
}
int main() {
string str;
cin >> str;
cout << firstUniqueChar(str);
}
import java.util.HashMap;
import java.util.Scanner;
public class UniqueCharacter {
public static char firstUniqueChar(String str) {
HashMap<Character, Integer> charCount = new HashMap<>();
for (char ch : str.toCharArray()) {
charCount.put(ch, charCount.getOrDefault(ch, 0) + 1);
}
for (char ch : str.toCharArray()) {
if (charCount.get(ch) == 1) {
return ch;
}
}
return '-';
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
System.out.println(firstUniqueChar(str));
scanner.close();
}
}
from collections import Counter
def first_unique_char(s):
char_count = Counter(s)
for ch in s:
if char_count[ch] == 1:
return ch
return '-'
s = input()
print(first_unique_char(s))
Problem Statement:
Given a string, find and print the first non-repeating character. If all characters repeat, print '-'
Input Format:
Output Format:
Example:
Input
ccbpa
Output
b
#include <iostream>
#include <unordered_map>
using namespace std;
char firstUniqueChar(const string &s) {
unordered_map<char, int> freq;
// Count frequency of each character
for (char ch : s) {
freq[ch]++;
}
// Find the first non-repeating character
for (char ch : s) {
if (freq[ch] == 1) {
return ch;
}
}
return '-';
}
int main() {
string s;
cin >> s;
cout << firstUniqueChar(s);
return 0;
}
import java.util.*;
public class Main {
public static char firstUniqueChar(String s) {
Map<Character, Integer> freq = new HashMap<>();
// Count frequency of each character
for (char ch : s.toCharArray()) {
freq.put(ch, freq.getOrDefault(ch, 0) + 1);
}
// Find the first non-repeating character
for (char ch : s.toCharArray()) {
if (freq.get(ch) == 1) {
return ch;
}
}
return '-';
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println(firstUniqueChar(s));
}
}
from collections import Counter
def first_unique_char(s):
char_count = Counter(s)
for ch in s:
if char_count[ch] == 1:
return ch
return '-'
s = input()
print(first_unique_char(s))
Problem Statement:
Given two sorted arrays, merge them into a single sorted array.
Input Format:
Output Format:
Example:
Input
3
1 3 5
4
2 4 6 8
Output
1 2 3 4 5 6 8
#include <iostream>
#include <vector>
using namespace std;
vector<int> mergeSortedArrays(vector<int>& arr1, vector<int>& arr2) {
int i = 0, j = 0;
vector<int> merged;
while (i < arr1.size() && j < arr2.size()) {
if (arr1[i] < arr2[j]) {
merged.push_back(arr1[i]);
i++;
} else {
merged.push_back(arr2[j]);
j++;
}
}
// Append remaining elements
while (i < arr1.size()) {
merged.push_back(arr1[i]);
i++;
}
while (j < arr2.size()) {
merged.push_back(arr2[j]);
j++;
}
return merged;
}
int main() {
int N, M;
cin >> N;
vector<int> arr1(N);
for (int i = 0; i < N; i++) {
cin >> arr1[i];
}
cin >> M;
vector<int> arr2(M);
for (int i = 0; i < M; i++) {
cin >> arr2[i];
}
vector<int> result = mergeSortedArrays(arr1, arr2);
for (int i = 0; i < result.size(); i++) {
cout << result[i] << " ";
}
return 0;
}
import java.util.*;
public class Main {
public static List<Integer> mergeSortedArrays(int[] arr1, int[] arr2) {
int i = 0, j = 0;
List<Integer> merged = new ArrayList<>();
while (i < arr1.length && j < arr2.length) {
if (arr1[i] < arr2[j]) {
merged.add(arr1[i]);
i++;
} else {
merged.add(arr2[j]);
j++;
}
}
// Append remaining elements
while (i < arr1.length) {
merged.add(arr1[i]);
i++;
}
while (j < arr2.length) {
merged.add(arr2[j]);
j++;
}
return merged;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr1 = new int[N];
for (int i = 0; i < N; i++) {
arr1[i] = sc.nextInt();
}
int M = sc.nextInt();
int[] arr2 = new int[M];
for (int i = 0; i < M; i++) {
arr2[i] = sc.nextInt();
}
List<Integer> result = mergeSortedArrays(arr1, arr2);
for (int num : result) {
System.out.print(num + " ");
}
}
}
def merge_sorted_arrays(arr1, arr2):
i = j = 0
merged = []
while i < len(arr1) and j < len(arr2):
if arr1[i] < arr2[j]:
merged.append(arr1[i])
i += 1
else:
merged.append(arr2[j])
j += 1
merged.extend(arr1[i:])
merged.extend(arr2[j:])
return merged
N = int(input())
arr1 = list(map(int, input().split()))
M = int(input())
arr2 = list(map(int, input().split()))
result = merge_sorted_arrays(arr1, arr2)
print(' '.join(map(str, result)))
This section includes some real sample coding questions that were designed to match the exact level of difficulty that you would find on the TCS Digital Coding Test. Each question allowed you to:
By working through a sequence of structured examples with explanations and solutions, you are not just learning to code; you are learning to think like a problem solver, which is really what TCS assesses.
Here are preparation tips to help you pass the TCS Digital Coding Round:
With the right preparation and consistent practice, TCS Coding Questions become predictable and manageable. The exam doesn't test how much code you remember; it evaluates how well you think, structure logic, and handle real-world problems efficiently.
The hiring trend is shifting toward skill-based screening. Good coders who understand logic and can debug quickly are preferred over those who memorize solutions. Your ability to solve coding challenges reflects how well you can contribute to real project tasks.
Yes. Usually, after passing the coding test, candidates typically go through one or more technical interviews, which will vary, but usually include discussing their solution and general technical knowledge.
No. Candidates are expected to solve the problems using their knowledge and skills without external help or resources.
The TCS Digital coding round is generally considered medium to hard. Questions are designed to test both your problem-solving skills and your understanding of data structures and algorithms.
You will typically be required to solve 3 coding questions in the Advanced Coding Round.
You will have 90 minutes to solve all three coding questions.
You can choose from a range of languages, including C, C++, Java, Python, C#, Erlang, Go, Haskell, Kotlin, Lua, Perl, Ruby, and Scala.
Each problem usually includes both visible and hidden test cases. Your score depends on the number of test cases your solution passes. Passing more test cases increases your chances of qualifying.
While the exact cut-off may vary, it is generally recommended to pass at least 4 out of 5 test cases per question to maximize your chances of advancing.
Yes. For some languages, especially C, you may be required to use command line arguments for input instead of standard input methods like scanf. Always read the instructions carefully on the exam platform.
No. Candidates are required to solve the problem using their knowledge and skills without any external assistance or resources.
Focus on practicing coding problems of medium to high difficulty, especially those involving arrays, strings, number theory, and data structures. Make sure you are comfortable with the allowed programming languages and understand the exam format.
Yes, you are typically allowed to choose a different programming language for each question. Select the language you are most comfortable with for each specific problem.
No, there is generally no negative marking for incorrect answers in the coding section. However, you should aim for accuracy to maximize your score.
In case of a tie, other factors such as time taken per question, accuracy, and performance in other assessment rounds may be considered by TCS for final selection.
NxtWave