Reasoning and Aptitude-Based Problems in TCS NQT
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.
What to Expect
You may encounter questions in the following areas:
- Numerical Ability: Basic math, arithmetic operations, percentages, ratios, averages, time and work, profit and loss, number systems, and more.
- Reasoning Ability: Series completion, analogies, syllogisms, blood relations, data arrangements, puzzles, visual reasoning, and pattern recognition.
- Verbal Ability: Vocabulary, reading comprehension, sentence correction, error detection, and fill-in-the-blank.
Common Problem Formats
- Questions with multiple choices: Choose the appropriate response from the given options.
- Quick Responses: Enter a word or a number as the response.
- Data Interpretation: Analyze tables, charts, or graphs and provide pertinent answers as part of data interpretation.
- Logical Sequences: Follow a pattern or sequence in a logical manner.
Example Problems
Numerical Ability Example
Problem:
If the cost price of an article is ₹200 and it is sold for ₹250, what is the profit percentage?
Solution:
Profit = 250 - 200 = ₹50
Profit % = (50/200) × 100 = 25%
Reasoning Ability Example
Problem:
Find the next number in the series: 2, 6, 12, 20, ?
Solution:
The pattern is n^2 + n:
1^2+1=2, 2^2+2=6, 3^2+3=12, 4^2+4=20
Next: 5^2+5=30
Verbal Ability Example
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
Tips for Success
- Read questions carefully: It is important to read carefully, as wording and constraints matter.
- Practice mental math: Speed and accuracy both matter.
- Familiarize yourself with common patterns, especially in reasoning and series questions.
- Practice previous years’ TCS NQT questions: This helps you understand the format and difficulty level.
TCS NQT Coding Question and Answers 2024
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:
1. 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
C
#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;
}
Java
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 + " ");
}
}
}
Python
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)
2. Jack loves Sundays. He wants to find out how many Sundays will occur in a month if he knows two things:
- The day on which the month starts (e.g., Monday, Tuesday, etc.)
- The total number of days in that month
Your task is to determine how many Sundays fall in that month based on this information.
Input
- A string indicating the first day of the month (e.g., "mon") and an integer representing the total number of days in that month.
Output
- The number of Sundays in that month.
Example
Input
mon
13
Output
2
C
#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;
}
Java
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);
}
}
Python
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))
₹ 49,000
Karthik was able to transform his career from a boring job to an
exciting job in software!
Talk to a career expert
3. 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 𝑁.
Output
The integer value after toggling all bits.
Example
Input:
10
Output:
5
C
#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;
}
Java
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);
}
}
Python
n = int(input())
bits = (1 << n.bit_length()) - 1 # Mask for toggle
print(n ^ bits)
4. 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
- The number of elements in the array is represented by the integer 𝑛(1 < n ≤ 100) in the first line.
- Each of the n integers in the second line can be either 0, 1, or 2.
Output
- Print the sorted array in a single line.
Example
Input
5
2 0 1 2 0
Output
0 0 1 2 2
C
#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;
}
Java
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();
}
}
Python
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)))
5. 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
- The number of gemstones n.
- The radiance values of the gemstones.
Output
- The count of gemstones that are more radiant than all previously collected ones.
Example
Input:
5
1 3 2 4 5
Output:
4
C
#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;
}
Java
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();
}
}
Python
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)
6. Problem Statement
Book names are kept in a lengthy string by a librarian.
It is your responsibility to examine that string and determine:
- The largest word, or the term with the most characters
- The first non-repeating character in the string
Words are separated by spaces. If there are no non-repeating characters, print -1.
Input Format
- A single string S (may include spaces)
Output Format
Print:
- The largest word
- The first non-repeating character
Example
Input:
welcome to tcs nqt challenge
Output:
challenge w
C
#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;
}
Java
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);
}
}
Python
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)
7. Problem Statement
Two players each type a word during a game. You must verify whether the two entered strings are anagrams of each other.
- If two strings have the same characters in any sequence but the same frequency, they are said to be anagrams.
- Ignore case and spaces.
Input Format
String A String B
Output Format
Print:
Anagram
or
Not Anagram
Example
Input:
Silent Listen
Output:
Anagram
C
#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;
}
Java
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");
}
}
Python
a = input().lower().replace(" ", "")
b = input().lower().replace(" ", "")
if sorted(a) == sorted(b):
print("Anagram")
else:
print("Not Anagram")
8. 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
n → number of elements arr → space-separated integers
Output Format
Print the sorted array in increasing order.
Example
Input:
5 10 2 45 3 7
Output:
2 3 7 10 45
C
#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;
}
Java
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 + " ");
}
}
Python
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)
8. 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:
The first line contains an integer n, the number of elements in the array.
The second line contains n space-separated integers.
Output:
Print each unique element followed by its frequency, in ascending order of elements.
Example:
Input: 8 4 5 6 4 5 4 7 6 Output: 4 3 5 2 6 2 7 1
C
#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;
}
Java
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();
}
}
Python
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])
Quick Summary – TCS NQT Coding Question and Answers 2025
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: Move zeroes, sort an array, sort a 0-1-2 array, count frequency, reverse an array.
- Handling strings: Find the largest words, find the first non-repeating character in a string; determine a palindrome and an anagram.
- Number Theory: Toggle bits, Fibonacci, factorial, prime checks, AP/GP series.
- Sorting & Algorithms: Bubble sort, single-pass sorts, custom order sorting.
- Real-World Problems: Problems presented using chocolates, gems, library books, or games to evaluate logical sense.
Each problem focuses on efficiency, clarity, and practical implementation, preparing candidates for coding screenings and technical interviews.
Conclusion
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.
Takeaway points:
- Focus on understanding problem patterns, not just memorizing solutions.
- Implement solutions in multiple languages like Python, Java, and C to improve adaptability.
- Prioritize optimized approaches for large inputs and time-sensitive questions.
- Solve scenario-based problems to strengthen analytical and reasoning skills.
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.
₹ 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. What are the common programming languages used for TCS NQT coding questions?
Candidates can use C, Java, Python, and other popular languages to solve coding questions in TCS NQT.
2. Are there any advanced coding questions in TCS NQT?
Yes, candidates may encounter advanced coding questions that require a deeper understanding and implementation of algorithms and data structures.
3. What types of number theory questions are commonly asked in TCS NQT?
You can expect questions on:
- Prime number checks
- Factorial and Fibonacci series calculations
- Armstrong, palindrome, perfect, and abundant numbers
- GCD and LCM computations
- Number system conversions (e.g., decimal to binary)
- Sum/product of digits
- AP/GP series
- Permutations and combinations
- Roots of quadratic equations
4. Will I need to code solutions for these problems, or are they multiple-choice?
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.
5. How should I approach problems involving large numbers or series?
- Use efficient algorithms to avoid timeouts (e.g., check for primes up to √N, use iterative methods for Fibonacci).
- For factorials or series with large results, be aware of integer overflow and use appropriate data types.
- Read the constraints carefully to decide whether a brute-force or optimized approach is needed.
6. Are number system conversions (like decimal to binary) important for TCS NQT?
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.
7. What types of string manipulation problems are common in TCS NQT?
You may face coding questions like:
- Determine if a string is a palindrome or an anagram.
- Check if an expression has balanced parentheses.
- Count the frequency of characters, vowels, or consonants.
- Remove duplicates or certain characters from a string.
- Find a non-repeating character or the longest word from a sentence.
- Reversing a string or sorting characters in lexicographic alphabet order
- Working with wildcard characters in pattern matching
- Implementing logic to reverse a string or sort characters in a string
- Detecting or generating fake palindromes
8. What types of array problems are commonly asked in TCS NQT?
You may encounter coding questions such as:
- Find the smallest number in an array or find the largest number in an array
- Second largest number in an array
- Reverse a given array
- Rotate array by k elements – block swap algorithm
- Remove duplicates from a sorted array or remove duplicates from an unsorted array
- Determine how frequently each element appears in an array
- Find all repeating elements in an array
- Finding the equilibrium index of an array
- Maximum product subarray in an array
- Searching for an element in an array