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.
Key Highlights of the Blog
- Concept-driven challenges: Focus on logic, data structures, and problem-solving, not just syntax.
- Real coding patterns: A selection of questions on arrays, strings, sorts, and mathematical problems that an NQT may reasonably have used in their exam.
- Time-bound efficiency: The questions test your ability to write optimized code while working within tight time constraints.
- Level-wise difficulty: The questions range from simple logic questions to pattern questions and algorithms.
- Language flexibility: Solve the questions in C, C++, Java, or Python; whatever you feel confident in.
- Placement-focused prep: Each problem strengthens the skills TCS values: clarity, logic, and clean coding.
What is TCS Digital?
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.
Types of Coding Problems in TCS Digital
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:
- Arrays
- Linked Lists
- Trees
- Graphs
- Sorting Algorithms
- Optimization Problems
- Subproblems
- Locally Optimal Choices
- String Processing
- Pattern Matching
- Number Theory
- Mathematical Concepts
Number of Questions and Duration
- Total Questions: 3 coding questions
- Total Duration: 90 minutes (all questions must be solved within this period)
Allowed Programming Languages
Candidates can choose from a wide range of programming languages, including:
- C
- C++
- Java (Java 7 and above)
- Python 3
- Perl
This flexibility allows you to code in the language you are most comfortable with.
Marking Scheme and Test Cases
- Each coding problem typically includes 2 visible and 3 hidden test cases.
- Your solution is evaluated against all test cases, but you can only see the results of the visible ones during the test.
- The overall score depends on how many test cases your solution passes. The more test cases you pass, the higher your score.
- To qualify, you must pass a minimum number of test cases (the cut-off may vary, but typically running at least 4 out of 5 test cases is recommended).
Special Instructions and Platform Details
- The coding environment is usually based on an Eclipse-like online compiler.
- For C language questions, standard input methods such as scanf, getc, or getchar are often not allowed. Instead, you may be required to use command line arguments to receive input.
- Familiarize yourself with command line argument handling and avoid using restricted keywords in your code.
Key Points to Remember
- Choose your programming language wisely based on your strengths.
- Pay close attention to input/output requirements and platform restrictions.
- Focus on writing code that is robust enough to handle both visible and hidden test cases.
Understanding the exam structure will help you manage your time effectively and avoid common pitfalls during the TCS Digital coding assessment.
Coding Question Categories and Patterns
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.
1. Arrays and Lists
It is common for questions to involve arrays or lists. For example, you may be asked to:
- Rotate, reverse, sort arrays
- Find the max or min element
- Remove duplicates
- Search for certain values or patterns
2. String Manipulation
Questions focused on strings are designed to test your ability to process and analyze text data. Examples include:
- Reverse a string or reverse words in a string
- Test if a string is a palindrome
- Count unique or repeating characters
- Pattern matching and substring
3. Number Theory
Questions in this category test your ability to apply mathematical logic, such as:
- Determine if a number is prime and analyze factors
- Calculate GCD or LCM
- Determine whether a number is an Armstrong number
- Analyze a number sequence or series
4. Linked Lists
Questions on linked lists assess your understanding of dynamic data types. You may be asked to:
- Merge, invert, or detect a loop in a linked list
- Find the middle node or the nth node
- Eliminate duplicates or a specific item
5. Trees
Questions based on trees can include:
- Traversal (inorder, preorder, postorder)
- Searching for a certain element
- Finding height or depth
- Check for a balanced tree
6. Pattern Printing
You may see questions that require printing certain patterns using loops, such as:
- Pyramids, triangles, etc.
- Numeric or character patterns
7. Problem-Solving and Edge Cases
Some questions test your ability to reason and work through scenarios, or edge cases.
- Finding missing numbers in a sequence
- Handling large inputs or special constraints
- Implementing efficient algorithms for time-sensitive problems
8. Searching and Sorting
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.
Sample Coding Questions and Solutions Asked in TCS Digital Coding Test
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.
1. Given an array Arr[] of N integers and a positive integer K, cyclically rotate the array clockwise by K.
Input Format:
- First line: N (number of elements)
- Second line: N space-separated integers (array elements)
- Third line: K (number of rotations)
Output Format:
- Rotated array as space-separated integers
Example
Input
5
10 20 30 40 50
2
Output
40 50 10 20 30
C++
#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] << ' ';
}
}
Java
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();
}
}
Python
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)))
2. 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:
- Single integer: count of numbers without repeated digits
Input
11
15
Output
4
C++
#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);
}
Java
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();
}
}
Python
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))
3. Given a string, split it into exactly 3 palindromic substrings. If it's not possible, print "Impossible".
Input Format:
Output Format:
- Three lines: each palindromic substring, or "Impossible"
Example
Input
nayannamantenet
Output
nayan
naman
tenet
C++
#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);
}
Java
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();
}
}
Python
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)
₹ 49,000
Karthik was able to transform his career from a boring job to an
exciting job in software!
Talk to a career expert
4. 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:
- First line: low high
- Second line: K
Output Format:
- Single integer: number of valid permutations
Example
Input
4 5
3
Output
4
C++
#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);
}
Java
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();
}
}
Python
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))
5. Given a string, find the first non-repeating character.
Example
Input
ccbp
Output
b
C++
#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 '-'; // or any indication of no unique character
}
int main() {
string str;
cin >> str;
cout << firstUniqueChar(str);
}
Java
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 '-'; // or any indication of no unique character
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
System.out.println(firstUniqueChar(str));
scanner.close();
}
}
Python
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 '-' # or any indication of no unique character
s = input()
print(first_unique_char(s))
6. Given a string, find and print the first non-repeating character. If all characters repeat, print '-'
Input Format:
Output Format:
- Single character: the first non-repeating character, or '-' if none exists
Example:
Input
ccbpa
Output
b
C++
#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;
}
Java
#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;
}
Python
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))
7. Given two sorted arrays, merge them into a single sorted array.
Input Format:
- First line: N (the number of elements in the first array)
- Second line: N space-separated integers (the first array)
- Third line: M (the number of elements in the second array)
- Fourth line: M space-separated integers (the second array)
Output Format:
- Single line: merged sorted array as space-separated integers
Example:
Input
31 3 542 4 6 8
Output1
2 3 4 5 6 8
C++
#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;
}
Java
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 + " ");
}
}
}
Python
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)))
Anchor Summary — What Have We Learned So Far?
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:
- How to figure out the logic behind the problem
- How to take the logic and convert it into efficient code
- How to be diligent about edge cases and optimize a solution as needed
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.
Preparation Tips and Strategies for Cracking TCS Digital Coding Round
Here are preparation tips to help you pass the TCS Digital Coding Round:
- Know each data structure and algorithm thoroughly.
- Use sites like LeetCode, HackerRank, or CodeSignal to practice.
- During the exam, budget your time wisely for each question depending on the difficulty.
- Always strive to optimize your solution/code, whether it be time or space complexity.
- Practice mock interviews to simulate the interview coding experience.
Tips for Cracking TCS Digital Coding Round
Here, are the tips to clear TCS Digital Coding Round:
- Make sure you have a strong understanding of data structures and algorithms.
- Use platforms like LeetCode, HackerRank, or CodeSignal to practice.
- During the exam, allocate time wisely to each question based on difficulty.
- Always look for ways to optimize your code for better performance.
- Engage in mock interviews to simulate the coding interview environment.
Conclusion
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.
Points to Remember
- Coding questions revolve around core concepts: arrays, strings, sorting, number theory, and pattern problems.
- TCS values logical thinking + clean, optimized code, not lengthy solutions.
- Consistency beats intensity; solving 1–2 coding problems daily builds confidence and speed.
- Focus on edge cases and input/output formatting; many students lose marks here.
Why This Matters for 2025
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.
₹ 49,000
Karthik was able to transform his career from a boring job to an
exciting job in software!
Talk to a career expert
Frequently Asked Questions
1. Is there an interview after the coding test?
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.
2. Can I use online resources during the coding test?
No. Candidates are expected to solve the problems using their knowledge and skills without external help or resources.
3. What is the difficulty level of the TCS Digital coding round?
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.
4. How many coding questions are asked in the TCS Digital recruitment drive?
You will typically be required to solve 3 coding questions in the Advanced Coding Round.
5. What is the total time allotted for the coding round?
You will have 90 minutes to solve all three coding questions.
6. What programming languages can I use in the TCS Digital coding round?
You can choose from a range of languages, including C, C++, Java, Python, C#, Erlang, Go, Haskell, Kotlin, Lua, Perl, Ruby, and Scala.
7. How is the marking scheme structured for the coding questions?
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.
8. What is the cut-off for the coding round?
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.
9. Are there any special instructions for input and output in the coding round?
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.
10. Is the TCS Digital coding round different from the normal TCS coding round?
No. Candidates are required to solve the problem using their knowledge and skills without any external assistance or resources.
11. How can I prepare for the TCS Digital coding round?
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.
12. Can I switch programming languages between different questions in the TCS Digital coding round?
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.
13. Is there negative marking in the TCS Digital coding round?
No, there is generally no negative marking for incorrect answers in the coding section. However, you should aim for accuracy to maximize your score.
14. How are ties resolved if multiple candidates have the same 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.