|company guide

How to Crack TCS Coding Interviews in 2026

Complete guide to TCS coding interviews — question patterns, difficulty breakdown, must-practice topics, and preparation strategy.

Tata Consultancy Services is one of the largest IT services companies in the world, and their hiring process reflects the scale at which they operate. TCS recruits thousands of engineers annually, particularly through their National Qualifier Test (NQT) for freshers and lateral hiring drives for experienced professionals. The coding component of TCS interviews is designed to filter for solid fundamentals rather than algorithmic wizardry — they want engineers who can write correct, efficient code for real-world problems.

For campus hires, the process typically includes the TCS NQT (aptitude + coding), followed by a technical interview and an HR round. Lateral hires usually face a phone screen, one or two technical coding rounds, and a managerial interview. The coding questions tend to be more practical and less puzzle-oriented compared to FAANG companies.

By the Numbers

TCS has 217 questions in the CodeJeet database. The difficulty distribution is notably beginner-friendly:

  • Easy: 94 questions (43%) — Nearly half the bank. TCS interviews are accessible if you have strong basics.
  • Medium: 103 questions (47%) — The other half of the equation. Comfortable with Easy? These are your next target.
  • Hard: 20 questions (10%) — A small slice. Hard problems are rare in TCS interviews, but experienced candidates may encounter them.

The 43/47/10 distribution is the most forgiving among major tech companies. This does not mean the interview is easy — it means the bar is on consistent execution rather than solving exotic problems under pressure.

Top Topics to Focus On

Array — The dominant category by a wide margin. TCS loves straightforward array problems: searching, sorting, rotation, subarray operations. If you can handle arrays fluently, you have already covered a significant portion of the question pool.

Let's look at a classic array problem: rotating an array to the right by k steps. The brute-force approach would shift elements one step at a time, but a more efficient method involves reversing parts of the array.

def rotate_array(nums, k):
    """
    Rotate the array to the right by k steps in-place.
    """
    n = len(nums)
    k = k % n  # Handle cases where k >= n

    # Helper function to reverse a portion of the array
    def reverse(start, end):
        while start < end:
            nums[start], nums[end] = nums[end], nums[start]
            start += 1
            end -= 1

    # Reverse the entire array
    reverse(0, n - 1)
    # Reverse the first k elements
    reverse(0, k - 1)
    # Reverse the remaining n-k elements
    reverse(k, n - 1)
    return nums

# Example usage
arr = [1, 2, 3, 4, 5, 6, 7]
print(rotate_array(arr, 3))  # Output: [5, 6, 7, 1, 2, 3, 4]

String — String reversal, substring extraction, palindrome detection, and basic pattern matching come up regularly. TCS questions in this area tend to be implementation-focused rather than tricky.

A common problem is checking if a string is a palindrome. A palindrome reads the same forwards and backwards. The efficient approach uses the two-pointer technique.

def is_palindrome(s):
    """
    Check if a string is a palindrome, ignoring non-alphanumeric characters and case.
    """
    left, right = 0, len(s) - 1
    while left < right:
        # Skip non-alphanumeric characters
        while left < right and not s[left].isalnum():
            left += 1
        while left < right and not s[right].isalnum():
            right -= 1
        # Compare characters case-insensitively
        if s[left].lower() != s[right].lower():
            return False
        left += 1
        right -= 1
    return True

# Example usage
print(is_palindrome("A man, a plan, a canal: Panama"))  # Output: True
print(is_palindrome("race a car"))  # Output: False

Hash Table — Frequency counting, duplicate detection, and lookup-based problems. TCS string and array problems often have optimal solutions that use hash maps, so treat this as a complementary skill rather than a standalone topic.

Finding the first non-repeating character in a string is a classic hash table problem. We can use a dictionary (or map) to store character frequencies.

def first_non_repeating_char(s):
    """
    Return the first non-repeating character in a string, or '_' if none exists.
    """
    freq = {}
    # First pass: count frequencies
    for char in s:
        freq[char] = freq.get(char, 0) + 1
    # Second pass: find the first character with frequency 1
    for char in s:
        if freq[char] == 1:
            return char
    return '_'

# Example usage
print(first_non_repeating_char("swiss"))  # Output: 'w'
print(first_non_repeating_char("aabb"))   # Output: '_'

Two Pointers — Problems involving pair sums on sorted arrays, removing duplicates in place, and merging sorted collections. The two-pointer technique converts many O(n^2) brute-force approaches into O(n) solutions, and TCS interviewers appreciate seeing that optimization.

A classic two-pointer problem is finding a pair in a sorted array that sums to a target value.

def two_sum_sorted(nums, target):
    """
    Return the indices (1-indexed) of two numbers in a sorted array that sum to target.
    Assumes exactly one solution exists.
    """
    left, right = 0, len(nums) - 1
    while left < right:
        current_sum = nums[left] + nums[right]
        if current_sum == target:
            return [left + 1, right + 1]  # 1-indexed
        elif current_sum < target:
            left += 1
        else:
            right -= 1
    return []  # No solution found

# Example usage
print(two_sum_sorted([2, 7, 11, 15], 9))  # Output: [1, 2]

Math — This is where TCS stands out from other companies. Expect problems involving number theory basics: GCD/LCM, prime checking, digit manipulation, modular arithmetic, and factorial computations. Brush up on mathematical reasoning.

Computing the Greatest Common Divisor (GCD) using Euclid's algorithm is fundamental. The GCD of two numbers is the largest number that divides both of them without leaving a remainder.

def gcd(a, b):
    """
    Compute the Greatest Common Divisor of a and b using Euclid's algorithm.
    """
    while b != 0:
        a, b = b, a % b
    return abs(a)

# Example usage
print(gcd(48, 18))  # Output: 6
print(gcd(101, 103))  # Output: 1 (primes)

Another common math problem is checking if a number is prime. A prime number is greater than 1 and has no positive divisors other than 1 and itself. We can optimize by checking divisors only up to the square root of the number.

def is_prime(n):
    """
    Check if a number is prime.
    """
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    # Check odd divisors up to sqrt(n)
    i = 3
    while i * i <= n:
        if n % i == 0:
            return False
        i += 2
    return True

# Example usage
print(is_prime(17))  # Output: True
print(is_prime(25))  # Output: False

Preparation Strategy

Weeks 1-2: Master the Basics

Spend the first two weeks on Easy problems exclusively. Solve 4 to 5 per day across arrays, strings, and math. The goal is speed and accuracy — you should be able to solve any Easy-level array or string problem in under 15 minutes. Pay special attention to math problems, as they are more prominent in TCS interviews than at most other companies.

A good starting problem is finding the maximum element in an array. While simple, it tests your ability to handle edge cases (empty array) and iterate efficiently.

def find_max(arr):
    if not arr:
        return None  # or raise an exception
    max_val = arr[0]
    for num in arr[1:]:
        if num > max_val:
            max_val = num
    return max_val

# Example usage
print(find_max([3, 5, 2, 8, 1]))  # Output: 8

Weeks 3-4: Move to Medium

Transition to medium-difficulty problems. Focus on two-pointer techniques, hash table patterns, and string manipulation problems that require more careful logic. Aim for 2 to 3 mediums per day. When you get stuck, spend no more than 20 minutes before reading the approach (not the code) and then implementing it yourself.

A classic medium problem is "3Sum": finding all unique triplets in an array that sum to zero. This builds on the two-sum concept and requires careful handling of duplicates.

def three_sum(nums):
    """
    Return all unique triplets in nums that sum to zero.
    """
    nums.sort()
    result = []
    n = len(nums)
    for i in range(n - 2):
        # Skip duplicate starting elements
        if i > 0 and nums[i] == nums[i - 1]:
            continue
        left, right = i + 1, n - 1
        while left < right:
            current_sum = nums[i] + nums[left] + nums[right]
            if current_sum == 0:
                result.append([nums[i], nums[left], nums[right]])
                # Skip duplicates for left and right pointers
                while left < right and nums[left] == nums[left + 1]:
                    left += 1
                while left < right and nums[right] == nums[right - 1]:
                    right -= 1
                left += 1
                right -= 1
            elif current_sum < 0:
                left += 1
            else:
                right -= 1
    return result

# Example usage
print(three_sum([-1, 0, 1, 2, -1, -4]))  # Output: [[-1, -1, 2], [-1, 0, 1]]

Week 5: Full-Length Practice Tests

Simulate the TCS NQT coding section. Set a timer for 60 minutes and attempt 2 to 3 problems of mixed difficulty. Practice on platforms that offer timed contests. The NQT is as much about time management as it is about problem-solving ability.

A typical mixed-difficulty set might include:

  1. Easy: Reverse a string.
  2. Medium: Find the longest substring without repeating characters.
  3. Hard (less common): Trapping Rain Water problem.

Let's look at the Medium problem: finding the length of the longest substring without repeating characters. This uses the sliding window technique with a hash set.

def length_of_longest_substring(s):
    """
    Return the length of the longest substring without repeating characters.
    """
    char_set = set()
    left = 0
    max_length = 0
    for right in range(len(s)):
        # If duplicate found, shrink window from the left
        while s[right] in char_set:
            char_set.remove(s[left])
            left += 1
        char_set.add(s[right])
        max_length = max(max_length, right - left + 1)
    return max_length

# Example usage
print(length_of_longest_substring("abcabcbb"))  # Output: 3 ("abc")

Week 6: Weak Spots and Review

Identify your weakest topic area and spend three days doing targeted practice. Then spend the remaining days revisiting problems you previously solved — can you solve them faster now? Can you explain the approach without looking at your code?

For example, if your weak spot is dynamic programming, start with the classic Fibonacci sequence problem, then move to more complex problems like the coin change problem.

def fibonacci(n, memo={}):
    """
    Compute the nth Fibonacci number using memoization (top-down DP).
    """
    if n in memo:
        return memo[n]
    if n <= 1:
        return n
    memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo)
    return memo[n]

# Example usage
print(fibonacci(10))  # Output: 55

Key Tips

  1. Do not underestimate the aptitude section. The TCS NQT includes quantitative aptitude, verbal ability, and logical reasoning alongside coding. Many candidates focus entirely on coding and lose points on sections that are equally weighted. Allocate preparation time for aptitude.

  2. Prioritize correctness over cleverness. TCS interviewers value clean, working code that handles all test cases. A brute-force solution that passes is better than an optimized solution with bugs. Get it working first, then optimize.

  3. Practice math fundamentals. Unlike most tech companies, TCS frequently tests mathematical reasoning. Be comfortable with prime sieves, digit-sum calculations, and number conversion problems. These are easy points if you have practiced them.

  4. Prepare for the technical interview beyond coding. TCS technical rounds often include questions on data structures theory (explain how a hash map works internally), operating systems, databases, and networking. Do not treat it as a pure coding interview.

  5. Write code in the language you know best. TCS typically allows multiple programming languages. Choose the one you are most fluent in rather than the one you think looks most impressive. Fluency reduces bugs and saves time.

Browse all TCS questions on CodeJeet

Related Articles