Published: 11 Nov 2025 | Reading Time: 3 min read
Did you prepared to complete one of India's most competitive new recruit assessments? In addition to testing your programming abilities, the TCS NQT Coding questions measure your ability to think critically and solve problems. Every topic challenges you to think like a software engineer, whether you're working with strings, optimizing arrays, solving mathematical problems, or putting traditional methods into practice.
In this blog, we'll break down the important coding topics, typical problem formats, and sample questions that are most likely to appear in TCS NQT 2024. By the end, you'll know exactly how to approach these problems, improve your coding efficiency, and step into the exam hall with confidence.
TCS NQT Coding Questions are the gateway to your dream job at Tata Consultancy Services. From arrays and strings to number theory and advanced algorithms, these problems test your logic, problem-solving skills, and coding efficiency. Mastering these topics in Python, Java, or C can dramatically boost your chances of cracking the TCS NQT in 2025.
TCS NQT coding questions are developed to test a candidate's problem-solving and coding abilities. These questions can vary in complexity, testing a range of skills from basic programming constructs to advanced algorithmic problem-solving. Candidates typically encounter problems that require them to write code in popular programming languages like C, Java and Python.
The TCS NQT typically consists of multiple rounds, including:
This initial round assesses logical reasoning, quantitative aptitude, and verbal ability.
Candidates are required to solve coding questions within a specified timeframe. This is the key focus for many aspirants.
Following the coding round, selected candidates often face technical interviews where they may be asked to explain their solutions or related technical questions.
The final round usually involves an interview focusing on soft skills and cultural fit.
Here are the topics asked in TCS NQT coding questions:
Reasoning and aptitude-based questions will be an important part of the assessment; your analytical thinking, numerical skill, and verbal reasoning will be evaluated in the core areas exam and are necessary to do well in the coding rounds if at all.
You may encounter questions in the following areas:
Problem: If the cost price of an article is ₹200 and it is sold for ₹250, what is the profit percentage?
Solution:
Problem: Find the next number in the series: 2, 6, 12, 20, ?
Solution:
Problem: Choose the correct word to fill the blank: "He ___ to the market every Sunday."
A) go B) going C) goes D) gone
Answer: C) goes
Here, we have provided some TCS NQT coding questions and answers to help you understand the format and type of questions you may encounter during the assessment:
Problem Statement:
Workers are packaging chocolates into packages in a busy chocolate factory. An array of integers is used to represent each packet, with 0 denoting an empty packet. It is your responsibility as the factory manager to locate every empty packet and move it to the end of the array.
Example:
Input
N = 8
arr = [4, 5, 0, 1, 9, 0, 5, 0]
Output
4 5 1 9 5 0 0 0
#include <stdio.h>
void moveZeroes(int arr[], int n) {
int count = 0; // Count of non-zero elements
for (int i = 0; i < n; i++)
if (arr[i] != 0)
arr[count++] = arr[i]; // Move non-zero elements forward
while (count < n)
arr[count++] = 0; // Fill remaining with zeros
}
int main() {
int arr[] = {4, 5, 0, 1, 9, 0, 5, 0};
int n = sizeof(arr) / sizeof(arr[0]);
moveZeroes(arr, n);
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}
public class MoveZeroes {
public static void moveZeroes(int[] arr) {
int count = 0; // Count of non-zero elements
for (int i = 0; i < arr.length; i++)
if (arr[i] != 0)
arr[count++] = arr[i];
while (count < arr.length)
arr[count++] = 0; // Fill remaining with zeros
}
public static void main(String[] args) {
int[] arr = {4, 5, 0, 1, 9, 0, 5, 0};
moveZeroes(arr);
for (int num : arr) {
System.out.print(num + " ");
}
}
}
def move_zeroes(arr):
count = 0 # Count of non-zero elements
for num in arr:
if num != 0:
arr[count] = num
count += 1
while count < len(arr):
arr[count] = 0
count += 1
arr = [4, 5, 0, 1, 9, 0, 5, 0]
move_zeroes(arr)
print(arr)
Problem Statement:
Jack loves Sundays. He wants to find out how many Sundays will occur in a month if he knows two things:
Your task is to determine how many Sundays fall in that month based on this information.
Input:
Output:
Example:
Input
mon
13
Output
2
#include <stdio.h>
#include <string.h>
int main() {
char s[4];
scanf("%s", s);
int days;
scanf("%d", &days);
char weekdays[][4] = {"mon", "tue", "wed", "thu", "fri", "sat", "sun"};
int offsets[] = {6, 5, 4, 3, 2, 1, 0};
int start = -1;
for (int i = 0; i < 7; i++) {
if (strcmp(s, weekdays[i]) == 0) {
start = offsets[i];
break;
}
}
int sundays = 0;
for (int i = 1; i <= days; i++) {
if ((start + i) % 7 == 0) {
sundays++;
}
}
printf("%d\n", sundays);
return 0;
}
import java.util.Scanner;
public class CountSundays {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String startDay = scanner.next();
int days = scanner.nextInt();
String[] weekdays = {"mon", "tue", "wed", "thu", "fri", "sat", "sun"};
int[] offsets = {6, 5, 4, 3, 2, 1, 0};
int start = -1;
for (int i = 0; i < 7; i++) {
if (startDay.equals(weekdays[i])) {
start = offsets[i];
break;
}
}
int sundays = 0;
for (int i = 1; i <= days; i++) {
if ((start + i) % 7 == 0) {
sundays++;
}
}
System.out.println(sundays);
}
}
def count_sundays(start_day, days):
weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
offsets = [6, 5, 4, 3, 2, 1, 0]
start = -1
for i in range(7):
if start_day == weekdays[i]:
start = offsets[i]
break
sundays = 0
for i in range(1, days + 1):
if (start + i) % 7 == 0:
sundays += 1
return sundays
# Input reading
start_day = input().strip()
days = int(input())
print(count_sundays(start_day, days))
Problem Statement:
Joseph has been thinking about numbers in his seminar on digital logic. He discovered an odd task in which he had to take a positive integer, convert it to binary, flip every bit beginning with the most important bit, and then determine the decimal value. Could you help him with this toggling challenge?
Input: A single integer N.
Output: The integer value after toggling all bits.
Example:
Input:
10
Output:
5
#include <stdio.h>
#include <math.h>
int main() {
int n;
scanf("%d", &n);
if (n == 0) {
printf("1\n");
return 0;
}
int k = (1 << (int)(log2(n) + 1)) - 1;
printf("%d\n", n ^ k);
return 0;
}
import java.util.Scanner;
public class ToggleChallenge {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = (1 << (Integer.SIZE - Integer.numberOfLeadingZeros(n))) - 1;
System.out.println(n ^ k);
}
}
n = int(input())
bits = (1 << n.bit_length()) - 1 # Mask for toggle
print(n ^ bits)
Problem Statement:
You are given an array consisting of only three distinct integers: 0, 1, and 2. Your task is to sort the array in a single pass, such that all 0's come first, followed by all 1's, and then all 2's.
Implement a function to achieve this and demonstrate its usage with an example.
Input:
Output:
Example:
Input
5
2 0 1 2 0
Output
0 0 1 2 2
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void sortArray(int arr[], int size) {
int low = 0, mid = 0, high = size - 1;
while (mid <= high) {
if (arr[mid] == 0) {
swap(&arr[low], &arr[mid]);
low++;
mid++;
} else if (arr[mid] == 1) {
mid++;
} else {
swap(&arr[mid], &arr[high]);
high--;
}
}
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sortArray(arr, n);
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
import java.util.Scanner;
public class SortArray {
public static void swap(int[] arr, int a, int b) {
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
public static void sortArray(int[] arr) {
int low = 0, mid = 0, high = arr.length - 1;
while (mid <= high) {
if (arr[mid] == 0) {
swap(arr, low, mid);
low++;
mid++;
} else if (arr[mid] == 1) {
mid++;
} else {
swap(arr, mid, high);
high--;
}
}
}
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();
}
sortArray(arr);
for (int i : arr) {
System.out.print(i + " ");
}
scanner.close();
}
}
def swap(arr, a, b):
arr[a], arr[b] = arr[b], arr[a]
def sort_array(arr):
low, mid, high = 0, 0, len(arr) - 1
while mid <= high:
if arr[mid] == 0:
swap(arr, low, mid)
low += 1
mid += 1
elif arr[mid] == 1:
mid += 1
else:
swap(arr, mid, high)
high -= 1
if __name__ == "__main__":
n = int(input())
arr = list(map(int, input().split()))
sort_array(arr)
print(" ".join(map(str, arr)))
Problem Statement:
A wise sage gathers gemstones in a magical country. Every time he gathers a new gemstone, he questions how many of them are more luminous than the ones he has already gathered. Can you assist the wise person in counting these glowing jewels?
Input:
Output:
Example:
Input:
5
1 3 2 4 5
Output:
4
#include <stdio.h>
#include <limits.h>
int main() {
int n;
scanf("%d", &n);
int count = 0, current_max = INT_MIN, value;
for (int i = 0; i < n; i++) {
scanf("%d", &value);
if (value > current_max) {
current_max = value;
count++;
}
}
printf("%d\n", count);
return 0;
}
import java.util.Scanner;
public class RadiantGems {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count = 0, currentMax = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int value = scanner.nextInt();
if (value > currentMax) {
currentMax = value;
count++;
}
}
System.out.println(count);
scanner.close();
}
}
n = int(input())
count = 0
current_max = float('-inf')
for _ in range(n):
value = int(input())
if value > current_max:
current_max = value
count += 1
print(count)
Problem Statement:
Book names are kept in a lengthy string by a librarian.
It is your responsibility to examine that string and determine:
Words are separated by spaces. If there are no non-repeating characters, print -1.
Input Format:
Output Format: Print:
Example:
Input:
welcome to tcs nqt challenge
Output:
challenge
w
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[200];
fgets(str, sizeof(str), stdin);
char largest[200];
char current[200];
int maxLen = 0;
int i = 0, j = 0;
while (1) {
if (str[i] == ' ' || str[i] == '\0' || str[i] == '\n') {
current[j] = '\0';
if (strlen(current) > maxLen) {
strcpy(largest, current);
maxLen = strlen(current);
}
j = 0;
if (str[i] == '\0')
break;
} else {
current[j++] = str[i];
}
i++;
}
int freq[256] = {0};
for (i = 0; str[i] != '\0'; i++) {
if (!isspace(str[i]))
freq[(unsigned char)str[i]]++;
}
char nonRepeat = '-';
for (i = 0; str[i] != '\0'; i++) {
if (!isspace(str[i]) && freq[(unsigned char)str[i]] == 1) {
nonRepeat = str[i];
break;
}
}
printf("%s\n", largest);
if (nonRepeat == '-')
printf("-1");
else
printf("%c", nonRepeat);
return 0;
}
import java.util.*;
public class StringManipulation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] words = str.split(" ");
String largest = "";
for (String word : words) {
if (word.length() > largest.length()) {
largest = word;
}
}
Map<Character, Integer> freq = new LinkedHashMap<>();
for (char c : str.toCharArray()) {
if (c != ' ')
freq.put(c, freq.getOrDefault(c, 0) + 1);
}
char nonRepeat = '-';
for (char c : str.toCharArray()) {
if (c != ' ' && freq.get(c) == 1) {
nonRepeat = c;
break;
}
}
System.out.println(largest);
System.out.println(nonRepeat == '-' ? -1 : nonRepeat);
}
}
s = input()
words = s.split()
largest = max(words, key=len)
freq = {}
for char in s:
if char != " ":
freq[char] = freq.get(char, 0) + 1
non_repeat = -1
for char in s:
if char != " " and freq[char] == 1:
non_repeat = char
break
print(largest)
print(non_repeat)
Problem Statement:
Two players each type a word during a game. You must verify whether the two entered strings are anagrams of each other.
Input Format:
Output Format: Print:
Example:
Input:
Silent
Listen
Output:
Anagram
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char a[100], b[100];
fgets(a, sizeof(a), stdin);
fgets(b, sizeof(b), stdin);
int freq[256] = {0};
for (int i = 0; a[i] != '\0'; i++) {
if (!isspace(a[i]))
freq[(unsigned char)tolower(a[i])]++;
}
for (int i = 0; b[i] != '\0'; i++) {
if (!isspace(b[i]))
freq[(unsigned char)tolower(b[i])]--;
}
for (int i = 0; i < 256; i++) {
if (freq[i] != 0) {
printf("Not Anagram");
return 0;
}
}
printf("Anagram");
return 0;
}
import java.util.*;
public class CheckAnagram {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine().toLowerCase().replace(" ", "");
String b = sc.nextLine().toLowerCase().replace(" ", "");
if (a.length() != b.length()) {
System.out.println("Not Anagram");
return;
}
int[] freq = new int[256];
for (char c : a.toCharArray())
freq[c]++;
for (char c : b.toCharArray())
freq[c]--;
for (int val : freq) {
if (val != 0) {
System.out.println("Not Anagram");
return;
}
}
System.out.println("Anagram");
}
}
a = input().lower().replace(" ", "")
b = input().lower().replace(" ", "")
if sorted(a) == sorted(b):
print("Anagram")
else:
print("Not Anagram")
Problem Statement:
You are given an integer array. Write a program to sort the array in increasing order using the Bubble Sort algorithm (without using built-in sort functions).
Input Format:
Output Format:
Example:
Input:
5
10 2 45 3 7
Output:
2 3 7 10 45
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}
import java.util.*;
public class BubbleSort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int num : arr)
System.out.print(num + " ");
}
}
n = int(input())
arr = list(map(int, input().split()))
for i in range(n - 1):
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
print(*arr)
Problem Statement:
You are given an array of integers. Your task is to count the frequency of each unique element in the array and print them in ascending order of the elements.
Input:
Output:
Example:
Input:
8
4 5 6 4 5 4 7 6
Output:
4 3
5 2
6 2
7 1
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 0; i < n; i++) {
int count = 1;
if (arr[i] != -1) {
for (int j = i + 1; j < n; j++) {
if (arr[i] == arr[j]) {
count++;
arr[j] = -1; // Mark as counted
}
}
printf("%d %d\n", arr[i], count);
}
}
return 0;
}
import java.util.*;
public class ArrayFrequency {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
Map<Integer, Integer> freq = new TreeMap<>();
for (int num : arr) {
freq.put(num, freq.getOrDefault(num, 0) + 1);
}
for (Map.Entry<Integer, Integer> entry : freq.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
sc.close();
}
}
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
freq = Counter(arr) # Count frequency of each element
for key in sorted(freq.keys()):
print(key, freq[key])
Here we will explore some of the most popular coding problems you will find in TCS NQT in 2025, along with sample solutions in Python, Java, and C. Types of problems to review and study will include:
Array Manipulation:
String Handling:
Number Theory:
Sorting & Algorithms:
Real-World Problems:
Each problem focuses on efficiency, clarity, and practical implementation, preparing candidates for coding screenings and technical interviews.
Preparing for TCS NQT Coding Questions requires more than just knowing syntax, it demands logical thinking, problem-solving skills, and efficient implementation. By practicing real-world coding problems on arrays, strings, number theory, and algorithms, you build the confidence to tackle both standard and advanced questions.
Consistent practice, revision of core topics, and solving past TCS NQT questions will give you a competitive edge, increasing your chances of success in the coding round and subsequent interviews.
Bottom Line: Master the fundamentals, practice strategically, and approach each coding problem methodically. This is the roadmap to excel in TCS NQT 2025.
Candidates can use C, Java, Python, and other popular languages to solve coding questions in TCS NQT.
Yes, candidates may encounter advanced coding questions that require a deeper understanding and implementation of algorithms and data structures.
You can expect questions on:
In the coding round, you will typically be required to write code to solve these problems. The logic must be implemented in your chosen programming language (like C, Java, or Python), and your code should handle various input formats as specified in the question.
Yes. Questions on converting numbers between decimal, binary, octal, and hexadecimal systems are frequent. Be sure to practice both manual conversion logic and built-in functions in your programming language.
You may face coding questions like:
You may encounter coding questions such as:
NxtWave provides industry-recognized IT certifications and career development programs for college students and early-career professionals. The platform offers comprehensive training in software development, data analysis, and emerging technologies including AI and generative AI tools.
Contact Information:
Course Offerings:
Source: NxtWave CCBP Blog Original URL: https://www.ccbp.in/blog/articles/tcs-nqt-coding-questions