LogoTauzand

TCS coding questions (2026)

By Aayush Kumar Gupta · Last updated · 248 questions tracked

Short answer: In this list, TCS Ninja questions are all Easy, Digital is mostly Medium and Prime is mostly Hard. Start with the main TCS top 10, then move to the list for the role you are aiming at.

TCS hires freshers through the TCS NQT. Based on how you do, you are considered for Ninja, Digital or Prime, and the coding questions get harder at each step. So it makes sense to prepare for the role you actually want, not just "TCS" in general.

The 10 to practise first

Sorted by how recently and how often TCS asked them. The line under each one is the trick that cracks it.

  1. 1.

    Best Time to Buy and Sell Stock · EasyAsked recently

    Walk once, remember the lowest price so far, and check today's price minus that. One pass, no extra array.

    Array, DP

  2. 2.

    Container With Most Water · MediumAsked recently

    Two pointers at both ends. Always move the shorter wall, because the taller one can't help you anymore.

    Array, Two Pointers, Greedy

  3. 3.

    Two Sum · EasyAsked recently

    One pass with a hash map: for each number, check whether target minus it is already in the map.

    Array, Hash Table

  4. 4.

    Longest Palindromic Substring · MediumAsked recently

    Expand around every centre, both odd and even length. O(n^2) and much easier to get right than the DP table.

    Two Pointers, String, DP

  5. 5.

    Roman to Integer · EasyAsked recently

    Go left to right. If a symbol is smaller than the one after it, subtract it; otherwise add it.

    Hash Table, Math, String

  6. 6.

    First Missing Positive · HardAsked recently

    Put every number x at index x-1 by swapping. Then the first index that doesn't hold the right number is your answer. O(n), no extra space.

    Array, Hash Table

  7. 7.

    Merge Sorted Array · EasyAsked recently

    Fill from the back. Start from the ends of both arrays so you never overwrite something you still need.

    Array, Two Pointers, Sorting

  8. 8.

    Remove Duplicates from Sorted Array · EasyAsked recently

    One slow pointer marks where the next unique value goes; the fast pointer scans. Return the slow pointer's count.

    Array, Two Pointers

  9. 9.

    Valid Anagram · EasyAsked recently

    Count letters in one string, subtract for the other, and check that everything is back to zero.

    Hash Table, String, Sorting

  10. 10.

    Fibonacci Number · EasyAsked recently

    Don't write the plain recursive version in an interview. Loop with two variables, or memoise if they ask for recursion.

    Math, DP, Recursion

Want all 248 TCS questions?

The full list is on the dashboard. You get 2 free company picks: choose TCS there and the full list opens free for you.

Pick TCS free 238 more inside

What TCS asks most

By topic: Array (58%), Hash Table (21%), String (21%), Math (17%) and Two Pointers (16%). By level, 43% of the list is Easy, 47% Medium and 10% Hard. 38 of the 248 were asked in the last 3 months.

TCS questions by topic

Array (144 of 248)

  1. 1.

    Find Missing Elements · EasyAsked recently

    Array, Hash Table, Sorting

  2. 2.

    Peak Index in a Mountain Array · MediumAsked recently

    Binary search: if arr[mid] < arr[mid+1] you're still climbing, so go right.

    Array, Binary Search, Ternary Search

  3. 3.

    Two Sum II - Input Array Is Sorted · MediumAsked recently

    The array is sorted, so use two pointers from both ends: sum too small, move left; too big, move right.

    Array, Two Pointers, Binary Search

Hash Table (52 of 248)

  1. 1.

    Group Anagrams · MediumAsked recently

    Use the sorted word (or a 26-letter count) as the key of a hash map, and collect words under it.

    Array, Hash Table, String

  2. 2.

    Integer to Roman · MediumAsked recently

    Greedy with a table that already includes 900, 400, 90, 40, 9 and 4. Keep taking the biggest value that fits.

    Hash Table, Math, String

  3. 3.

    Longest Consecutive Sequence · MediumAsked recently

    Put everything in a set. Only start counting from x when x-1 isn't in the set, so each run is counted once. O(n).

    Array, Hash Table, Union Find

String (51 of 248)

  1. 1.

    Valid Palindrome · EasyAsked recently

    Two pointers from both ends, skip anything that isn't a letter or digit, compare in lowercase.

    Two Pointers, String

  2. 2.

    Valid Parentheses · EasyAsked recently

    Stack. Push opening brackets; on a closing one, the top must be its match. The stack must be empty at the end.

    String, Stack, Bracket Sequences

  3. 3.

    Longest Common Prefix · EasyAsked recently

    Compare letter by letter across all words and stop at the first mismatch. Or sort and compare only the first and last word.

    Array, String, Trie

Math (43 of 248)

  1. 1.

    Integer Break · MediumAsked recently

    Break the number into as many 3s as you can (use a 4 instead of 3+1). DP also works if you want to show the reasoning.

    Math, DP

  2. 2.

    Palindrome Number · EasyAsked recently

    Negative numbers are out. Reverse only half the digits and compare, so there's no overflow to worry about.

    Math

  3. 3.

    Evaluate Reverse Polish Notation · MediumAsked recently

    Stack of numbers. On an operator, pop two, apply it (second popped is the left side), push the result. Division truncates towards zero.

    Array, Math, Stack

Two Pointers (39 of 248)

  1. 1.

    3Sum · MediumAsked recently

    Sort first. Fix one number, then run two pointers on the rest. Skip duplicates or you'll print the same triplet twice.

    Array, Two Pointers, Sorting

  2. 2.

    Palindrome Linked List · EasyAsked recently

    Find the middle with slow and fast pointers, reverse the second half, then compare both halves.

    Linked List, Two Pointers, Stack

  3. 3.

    Reorder List · MediumAsked recently

    Three steps: find the middle, reverse the second half, then merge the two halves one node at a time.

    Linked List, Two Pointers, Stack

Asked at TCS in the last 3 months

  1. 1.

    Reverse Linked List · EasyAsked recently

    Three pointers: prev, current, next. Point current back to prev and move all three forward. Know the recursive version too.

    Linked List, Recursion

  2. 2.

    Balanced Binary Tree · EasyAsked recently

    Return the height from each subtree, or -1 the moment one side is off by more than 1. One pass, not a height call per node.

    Tree, DFS

  3. 3.

    Find Peak Element · MediumAsked recently

    Binary search: if mid is smaller than mid+1, a peak is on the right; otherwise it's at mid or on the left.

    Array, Binary Search

  4. 4.

    Kth Largest Element in an Array · MediumAsked recently

    Min-heap of size k: the top is your answer at the end. Quickselect is faster on average if they push for it.

    Array, Divide and Conquer, Sorting

  5. 5.

    Kth Smallest Element in a BST · MediumAsked recently

    Inorder traversal of a BST gives sorted order. Stop at the kth node you visit.

    Tree, DFS, BST

TCS Ninja coding questions

15 questions · 100% Easy, 0% Medium, 0% Hard

  1. 1.

    Single Number · Easy

    XOR everything. Pairs cancel out and the single number is what's left.

    Bit Manipulation

  2. 2.

    Fizz Buzz · Easy

    Check 15 first, then 3, then 5. It's a warm-up; get it right in one go and move on.

    Math, String

  3. 3.

    Reverse Integer · Easy

    Pop digits with % 10 and build the result, but check for 32-bit overflow before every multiply.

    Math

  4. 4.

    Climbing Stairs · Easy

    It's Fibonacci in disguise: ways(n) = ways(n-1) + ways(n-2). Two variables are enough.

    DP

  5. 5.

    Palindrome Linked List · Easy

    Find the middle with slow and fast pointers, reverse the second half, then compare both halves.

    Linked List, Two Pointers

  6. 6.

    Merge Sorted Array · Easy

    Two Pointers

  7. 7.

    Valid Anagram · Easy

    String, Hash Table

  8. 8.

    Happy Number · Easy

    Keep summing the squares of digits. To catch the loop, use a set or slow and fast pointers.

    Math, Hash Table

  9. 9.
  10. 10.

    Remove Duplicates from Sorted List · Easy

    Walk the list and skip the next node while it has the same value. No extra memory.

    Linked List

See all 15 TCS Ninja questions (pick it as a free company)

TCS Digital coding questions

16 questions · 38% Easy, 62% Medium, 0% Hard

  1. 1.

    Maximum Depth of Binary Tree · Easy

    One line of recursion: 1 + max(depth of left, depth of right). BFS level by level works too.

    Tree, DFS

  2. 2.

    Find Minimum in Rotated Sorted Array · Medium

    Binary search against the right end: if mid is bigger than the right value, the minimum is on the right side.

    Binary Search

  3. 3.

    Sort Colors · Medium

    Dutch national flag: three pointers for the 0s, the current element and the 2s. One pass.

    Two Pointers, Array

  4. 4.

    Symmetric Tree · Easy

    Compare the left subtree with the mirror of the right: left.left with right.right, and left.right with right.left.

    Tree, DFS

  5. 5.

    Majority Element II · Medium

    Same voting idea, but with two candidates, since at most two numbers can appear more than n/3 times. Verify the counts at the end.

    Array

  6. 6.

    Same Tree · Easy

    Recursively compare: both empty, or same value with the same left and right subtrees.

    Tree, DFS

  7. 7.

    Search Insert Position · Easy

    Plain lower-bound binary search. When the loop ends, left is the answer.

    Binary Search

  8. 8.

    Set Matrix Zeroes · Medium

    Use the first row and column as markers to get O(1) space. Remember separately whether they had a zero themselves.

    Matrix

  9. 9.

    Product of Array Except Self · Medium

    Prefix products from the left, suffix products from the right, multiply them. No division needed.

    Array

  10. 10.

    Remove Element · Easy

    Two pointers: copy every value that isn't the target to the front. The count of copies is the answer.

    Two Pointers

See all 16 TCS Digital questions (pick it as a free company)

TCS Prime coding questions

13 questions · 0% Easy, 38% Medium, 62% Hard

  1. 1.

    Maximum Product Subarray · Medium

    Track both the max and the min product ending here, because a negative number flips them.

    DP

  2. 2.

    Edit Distance · Hard

    Classic 2D DP. dp[i][j] is the cost to turn the first i letters into the first j: take the min of insert, delete and replace.

    DP

  3. 3.
  4. 4.

    Longest Palindromic Substring · Medium

    String, DP

  5. 5.

    Top K Frequent Elements · Medium

    Count with a hash map, then use a min-heap of size k, or bucket sort by frequency for O(n).

    Heap

  6. 6.

    Best Time to Buy and Sell Stock IV · Hard

    DP over (day, transactions left, holding or not). If k is bigger than n/2 it turns into the unlimited-trades version.

    DP

  7. 7.

    Word Break · Medium

    dp[i] is true if some earlier dp[j] is true and s[j:i] is in the dictionary. Put the words in a set.

    DP

  8. 8.

    Longest Valid Parentheses · Hard

    Stack of indices with a -1 at the bottom as a base. The length is the current index minus the index on top of the stack.

    Stack, DP

  9. 9.

    Minimum Window Substring · Hard

    Sliding window with a count map. Grow the right side until the window is valid, then shrink the left as far as you can.

    Sliding Window

  10. 10.

    Course Schedule II · Medium

    Topological sort. Kahn's algorithm with in-degrees is the easiest to explain; if you can't take every course, there's a cycle.

    Graph, Topological Sort

See all 13 TCS Prime questions (pick it as a free company)

If you only have a week

  • Arrays are in more than half of the main TCS list. Do those first.
  • Going for Digital or Prime? Ninja-level questions won't be enough. Look at the Prime list below: Edit Distance, Maximum Product Subarray, First Missing Positive. That is the level.
  • DP shows up a lot more in Digital and Prime than in Ninja. Climbing Stairs is a fine warm-up, but don't stop there.
  • Questions marked "Asked recently" showed up in the last 3 months. Give them a little extra time.

From students who sat the TCS test

Sat the TCS test recently? Tell us which questions you got and we will add them here with your name. Share your experience

Common questions

What coding questions does TCS ask?

Right now the most common ones are Best Time to Buy and Sell Stock, Container With Most Water and Two Sum. The top 10 above is sorted by how recently and how often each one was asked.

Is the TCS coding round hard?

Mostly not. In this list, 43% of the questions are Easy, 47% Medium and 10% Hard.

Which topics should I study for TCS?

Start with Array (58%), Hash Table (21%) and String (21%). Together they cover most of the TCS list.

Is this the official TCS question bank?

No. Nobody outside TCS has that. This list comes from LeetCode company tags, where candidates report the questions they got. Treat it as the best public signal, not a guarantee.

How do I get the full TCS list?

Sign up on Tauzand and pick TCS as one of your 2 free companies. The full list opens free, with progress tracking.

How this page is made

The question list comes from the company tags on LeetCode, where candidates report the questions they were asked. We sort it by how recently and how often each question came up, and refresh it from the source regularly (this page: 3 Nov 2026). Every question links to the original problem; we don't copy problem statements. The one-line tricks, the topic breakdown and the tips are written and checked by Aayush Kumar Gupta and the Tauzand team. If you spot a mistake, tell us.