Introduction
The TCS NQT (National Qualifier Test) Digital and Prime roles require strong problem-solving skills, a deep understanding of data structures, and proficiency in algorithms. To help you crack the coding round, we’ve compiled the TCS NQT Top coding questions that have high chances of appearing in the exam. These questions cover essential topics such as arrays, strings, recursion, dynamic programming, and bit manipulation.
By practicing these questions, you will develop the ability to solve complex problems efficiently and improve your coding skills for the TCS NQT.
Top 20 MUST-DO Coding Questions for TCS NQT Digital/Prime
1. Sum of Cubes in a Given Range
This problem requires finding the sum of cubes of all numbers within a given range [n, m]
. You need to take two integers as input and compute the sum by iterating through the range. Understanding loops and basic arithmetic operations is crucial for solving this problem efficiently.
2. Sum of Prime Numbers in a Given Range
To solve this problem, you must determine all prime numbers between n
and m
and compute their sum. You need to implement a function to check whether a number is prime and use it within a loop to sum up all primes in the range. Efficient solutions leverage mathematical properties to optimize prime checking.
3. Find the First N Multiples of 10
In this question, you’re required to compute the sum of the first n
multiples of 10. By iterating through n
values and multiplying each by 10, you can determine the final sum. This problem strengthens your understanding of loops and mathematical operations.
4. Longest Subarray with Given Sum
This problem involves finding the longest contiguous subarray whose sum equals a given value K
. Using prefix sums or a hashmap-based approach can significantly optimize the solution. It’s an essential problem to understand sliding window techniques and hashing.
5. Find the XOR of All Subarrays
Here, the task is to compute the XOR of all possible subarrays within an array. This problem helps in understanding bitwise operations and how XOR works in different scenarios. Optimized approaches rely on mathematical properties of XOR.
6. Reverse a String
Given a string, the goal is to reverse it without using built-in functions like reverse()
. This problem tests your understanding of string manipulation, loops, and recursion. Efficient solutions include using two-pointer techniques or stack-based approaches.
7. Find the Largest Element in an Array
You need to find the maximum value in an array efficiently. The brute-force approach is to sort the array and pick the last element, but a more optimal solution involves iterating through the array and tracking the maximum value.
8. Check for Palindrome Number
A number is a palindrome if it reads the same forward and backward. The problem can be solved by reversing the number and checking if it matches the original. Techniques such as using a mathematical approach (without converting to a string) are optimal.
9. Fibonacci Series Using Recursion
The Fibonacci sequence follows the rule F(n) = F(n-1) + F(n-2)
, where F(0) = 0
and F(1) = 1
. Using recursion, we can generate the sequence, but this leads to redundant computations. Optimized approaches include memoization and iterative methods.
10. Binary Search Implementation
Binary search is an efficient way to find an element in a sorted array, working in O(log N)
time. The approach involves checking the middle element and recursively searching in the left or right half. This problem strengthens your understanding of divide-and-conquer techniques.
11. Find the Second Largest Number in an Array
The task is to determine the second-largest number without sorting. A simple approach involves maintaining two variables to track the maximum and second maximum while iterating through the array.
12. Merge Two Sorted Arrays
Given two sorted arrays, you need to merge them while maintaining order. The optimal approach involves using two pointers, comparing elements, and merging in O(N+M)
time instead of sorting the combined array.
13. Check if a Given String is a Valid Anagram
An anagram is a word formed by rearranging the letters of another word (e.g., “listen” and “silent”). You can solve this by sorting both strings and comparing them or by using frequency counting with a hash table.
14. Find the First Non-Repeating Character in a String
The goal is to find the first character that appears only once in a string. Using a hash map (dictionary) to store character frequencies allows us to determine the answer efficiently in a single pass.
15. Find the Maximum Subarray Sum using Kadane’s Algorithm
Kadane’s Algorithm efficiently finds the maximum sum of a contiguous subarray. Instead of checking all subarrays (which is slow), it dynamically updates a running sum and resets when necessary, running in O(N)
time.
16. Find the GCD of Two Numbers Using Euclidean Algorithm
The greatest common divisor (GCD) of two numbers is the largest number that divides both. The Euclidean algorithm simplifies the problem using the formula GCD(a, b) = GCD(b, a % b)
, running in O(log min(a, b))
time.
17. Find the LCM of Two Numbers
The least common multiple (LCM) of two numbers is the smallest number divisible by both. Using the formula LCM(a, b) = (a * b) / GCD(a, b)
, we can efficiently compute the result.
18. Check if a Given Number is Armstrong
An Armstrong number (e.g., 153) is equal to the sum of its digits raised to the power of the number of digits. The solution involves extracting digits, computing the sum, and checking against the original number.
19. Count the Number of Set Bits in an Integer
A set bit refers to a 1
in a number’s binary representation. Using bitwise operations, you can count set bits efficiently with approaches like Brian Kernighan’s algorithm, which runs in O(log N)
.
20. Generate All Subsets of a Given Set
Generating subsets is a fundamental problem in combinatorics. The most efficient approach uses bit masking (using binary representation) or recursion (backtracking) to list all possible subsets.
Final Words of Encouragement
Cracking the TCS NQT Digital/Prime coding round requires dedication and practice. By working through these must-do questions, you will significantly improve your problem-solving abilities. Remember:
- Focus on understanding concepts rather than memorization.
- Practice consistently to improve speed and accuracy.
- Attempt mock tests to simulate real exam conditions.
With the right preparation and determination, you can secure your spot in TCS Digital or Prime. Stay focused, keep coding, and believe in yourself!
Good luck! 🚀