Problem database last updated: June 20, 2025

Ttcs logo

tcs Coding Interview Questions

100 problems · 50 Easy, 45 Medium, 5 Hard · Ranked #12 of 458

Difficulty breakdown

50 Easy

50% · avg 23%

45 Medium

45% · avg 59%

5 Hard

5% · avg 18%

Top topics

array
57%
string
22%
math
20%1.6x
two-pointers
20%1.5x
hash-table
18%
dynamic-programming
18%

Interview profile

Based on 100 reported problems, tcs interviews are easier than average - only 5% Hard compared to 18% across all companies.

Compared to the industry average, tcs puts unusual emphasis on database (7% of problems, 6.2x the industry average), string-matching (2% of problems, 2.3x the industry average), memoization (3% of problems, 1.9x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (57%), string (22%), math (20%), two-pointers (20%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 100 problems

Two Sum

Solve

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.

EasyVery Likely
arrayhash-map

Palindrome Number

Solve

Given an integer x, return true if x is a palindrome, and false otherwise.

EasyVery Likely
math

Majority Element

Solve

Given an array nums of size n, return the majority element.

EasyLikely
arrayhash-tabledivide-and-conquer

Best Time to Buy and Sell Stock

Solve

You are given an array prices where prices[i] is the price of a given stock on the ith day.

EasyLikely
arraydynamic-programming

Maximum Subarray

Solve

Given an integer array nums, find the subarray with the largest sum, and return its sum.

MediumLikely
arraydivide-and-conquerdynamic-programming

Longest Common Prefix

Solve

Write a function to find the longest common prefix string amongst an array of strings.

EasyLikely
arraystringtrie

Valid Parentheses

Solve

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

EasyLikely
stringstack

Rotate Array

Solve

Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.

MediumLikely
arraymathtwo-pointers

Fibonacci Number

Solve

The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, startin...

EasyLikely
mathdynamic-programmingrecursion

Subarray Sum Equals K

Solve

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

MediumLikely
arrayhash-tableprefix-sum

Move Zeroes

Solve

Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.

EasyLikely
arraytwo-pointers

Reverse Integer

Solve

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1...

MediumLikely
math

Maximum Ascending Subarray Sum

Solve

Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums.

EasyLikely
array

Jump Game

Solve

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length...

MediumLikely
arraydynamic-programminggreedy

Count the Digits That Divide a Number

Solve

Given an integer num, return the number of digits in num that divide num.

EasyLikely
math

Palindrome Partitioning IV

Solve

Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.​​​​​

HardLikely
stringdynamic-programming

Remove Letter To Equalize Frequency

Solve

You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so th...

EasyLikely
hash-tablestringcounting

Minimum Cuts to Divide a Circle

Solve

A valid cut in a circle can be:

EasyLikely
mathgeometry

Minimum Operations to Exceed Threshold Value I

Solve

You are given a 0-indexed integer array nums, and an integer k.

EasyLikely
array

Merge Sorted Array

Solve

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and num...

EasyLikely
arraytwo-pointerssorting

Minimum Operations to Exceed Threshold Value II

Solve

You are given a 0-indexed integer array nums, and an integer k.

MediumLikely
arrayheap-priority-queuesimulation

Valid Anagram

Solve

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

EasyLikely
hash-tablestringsorting

Single Number

Solve

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

EasyLikely
arraybit-manipulation

Unique Paths

Solve

There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner...

MediumLikely
mathdynamic-programmingcombinatorics

Roman to Integer

Solve

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

EasyLikely
hash-tablemathstring

Bitwise ORs of Subarrays

Solve

Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty subarrays of arr.

MediumLikely
arraydynamic-programmingbit-manipulation

3Sum

Solve

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

MediumLikely
arraytwo-pointerssorting

Climbing Stairs

Solve

You are climbing a staircase. It takes n steps to reach the top.

EasyLikely
mathdynamic-programmingmemoization

Find the Index of the First Occurrence in a String

Solve

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

EasyLikely
two-pointersstringstring-matching

Longest Palindromic Substring

Solve

Given a string s, return the longest palindromic substring in s.

MediumLikely
two-pointersstringdynamic-programming

Remove Duplicates from Sorted Array

Solve

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order o...

EasyLikely
arraytwo-pointers

Second Highest Salary

Solve

Table: Employee

MediumSometimes
database

Plus One

Solve

You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most sig...

EasySometimes
arraymath

Container With Most Water

Solve

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

MediumSometimes
arraytwo-pointersgreedy

Pow(x, n)

Solve

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

MediumSometimes
mathrecursion

Sort Colors

Solve

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order...

MediumSometimes
arraytwo-pointerssorting

Length of Last Word

Solve

Given a string s consisting of words and spaces, return the length of the last word in the string.

EasySometimes
string

Happy Number

Solve

Write an algorithm to determine if a number n is happy.

EasySometimes
hash-tablemathtwo-pointers

Trapping Rain Water

Solve

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

HardSometimes
arraytwo-pointersdynamic-programming

Missing Number

Solve

Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

EasySometimes
arrayhash-tablemath

Reverse Words in a String

Solve

Given an input string s, reverse the order of the words.

MediumSometimes
two-pointersstring

Contains Duplicate

Solve

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

EasySometimes
arrayhash-tablesorting

Sliding Window Maximum

Solve

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see...

HardSometimes
arrayqueuesliding-window

Spiral Matrix

Solve

Given an m x n matrix, return all elements of the matrix in spiral order.

MediumSometimes
arraymatrixsimulation

Toeplitz Matrix

Solve

Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.

EasySometimes
arraymatrix

Best Time to Buy and Sell Stock II

Solve

You are given an integer array prices where prices[i] is the price of a given stock on the ith day.

MediumSometimes
arraydynamic-programminggreedy

Sqrt(x)

Solve

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.

EasySometimes
mathbinary-search

Merge Two Sorted Lists

Solve

You are given the heads of two sorted linked lists list1 and list2.

EasySometimes
linked-listrecursion

Set Matrix Zeroes

Solve

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.

MediumSometimes
arrayhash-tablematrix

Max Consecutive Ones III

Solve

Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.

MediumSometimes
arraybinary-searchsliding-window

Check if Array Is Sorted and Rotated

Solve

Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise,...

EasySometimes
array

Longest Substring Without Repeating Characters

Solve

Given a string s, find the length of the longest substring without duplicate characters.

MediumSometimes
hash-tablestringsliding-window

Add Two Numbers

Solve

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a sing...

MediumSometimes
linked-listmathrecursion

Department Top Three Salaries

Solve

Table: Employee

HardSometimes
database

Generate Parentheses

Solve

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

MediumSometimes
stringdynamic-programmingbacktracking

N-th Tribonacci Number

Solve

The Tribonacci sequence Tn is defined as follows:

EasySometimes
mathdynamic-programmingmemoization

Single Element in a Sorted Array

Solve

You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.

MediumSometimes
arraybinary-search

Add Binary

Solve

Given two binary strings a and b, return their sum as a binary string.

EasySometimes
mathstringbit-manipulation

4Sum

Solve

Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:

MediumSometimes
arraytwo-pointerssorting

Article Views I

Solve

Table: Views

EasySometimes
database

Find Customer Referee

Solve

Table: Customer

EasySometimes
database

K-diff Pairs in an Array

Solve

Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.

MediumSometimes
arrayhash-tabletwo-pointers

Reverse Linked List

Solve

Given the head of a singly linked list, reverse the list, and return the reversed list.

EasySometimes
linked-listrecursion

Fizz Buzz

Solve

Given an integer n, return a string array answer (1-indexed) where:

EasySometimes
mathstringsimulation

Reverse String

Solve

Write a function that reverses a string. The input string is given as an array of characters s.

EasySometimes
two-pointersstring

Same Tree

Solve

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

EasySometimes
treedepth-first-searchbreadth-first-search

Largest Number

Solve

Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

MediumSometimes
arraystringgreedy

Find First and Last Position of Element in Sorted Array

Solve

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.

MediumSometimes
arraybinary-search

Next Permutation

Solve

A permutation of an array of integers is an arrangement of its members into a sequence or linear order.

MediumSometimes
arraytwo-pointers

Pascal's Triangle

Solve

Given an integer numRows, return the first numRows of Pascal's triangle.

EasySometimes
arraydynamic-programming

Sort Array by Increasing Frequency

Solve

Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them...

EasySometimes
arrayhash-tablesorting

Edit Distance

Solve

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

MediumSometimes
stringdynamic-programming

Binary Search

Solve

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then ret...

EasySometimes
arraybinary-search

Longest Common Subsequence

Solve

Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

MediumSometimes
stringdynamic-programming

Remove Duplicates from Sorted Array II

Solve

Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative or...

MediumSometimes
arraytwo-pointers

Subsets

Solve

Given an integer array nums of unique elements, return all possible subsets (the power set).

MediumSometimes
arraybacktrackingbit-manipulation

Largest Rectangle in Histogram

Solve

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the his...

HardSometimes
arraystackmonotonic-stack

Rotate String

Solve

Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.

EasySometimes
stringstring-matching

Longest Consecutive Sequence

Solve

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

MediumSometimes
arrayhash-tableunion-find

Maximum Product Subarray

Solve

Given an integer array nums, find a subarray that has the largest product, and return the product.

MediumSometimes
arraydynamic-programming

Employee Bonus

Solve

Table: Employee

EasySometimes
database

Sort Characters By Frequency

Solve

Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the st...

MediumSometimes
hash-tablestringsorting

Power of Two

Solve

Given an integer n, return true if it is a power of two. Otherwise, return false.

EasySometimes
mathbit-manipulationrecursion

Search a 2D Matrix II

Solve

Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties:

MediumSometimes
arraybinary-searchdivide-and-conquer

Sum of Unique Elements

Solve

You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.

EasySometimes
arrayhash-tablecounting

Number of Employees Who Met the Target

Solve

There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.

EasySometimes
array

Big Countries

Solve

Table: World

EasySometimes
database

Path with Maximum Probability

Solve

You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the node...

MediumSometimes
arraygraphheap-priority-queue

Combination Sum

Solve

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum...

MediumSometimes
arraybacktracking

Word Search

Solve

Given an m x n grid of characters board and a string word, return true if word exists in the grid.

MediumSometimes
arraystringbacktracking

Partition List

Solve

Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

MediumSometimes
linked-listtwo-pointers

3Sum Closest

Solve

Given an integer array nums of length n and an integer target, find three integers at distinct indices in nums such that the sum is closest to target.

MediumSometimes
arraytwo-pointerssorting

How Many Numbers Are Smaller Than the Current Number

Solve

Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of val...

EasySometimes
arrayhash-tablesorting

Peak Index in a Mountain Array

Solve

You are given an integer mountain array arr of length n where the values increase to a peak element and then decrease.

MediumSometimes
arraybinary-search

Count Primes

Solve

Given an integer n, return the number of prime numbers that are strictly less than n.

MediumSometimes
arraymathenumeration

Product of Array Except Self

Solve

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

MediumSometimes
arrayprefix-sum

Coin Change

Solve

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.

MediumSometimes
arraydynamic-programmingbreadth-first-search

Students and Examinations

Solve

Table: Students

EasySometimes
database

Intersection of Two Arrays

Solve

Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any...

EasySometimes
arrayhash-tabletwo-pointers

First Unique Character in a String

Solve

Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

EasySometimes
hash-tablestringqueue

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent tcs interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your tcs coding interview

tcs interviews focus heavily on array, string, math problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. tcs interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does tcs ask in interviews?add

tcs has been reported to ask 100 distinct coding problems. The most common topics are array, string, math. 50 are Easy difficulty, 45 are Medium, and 5 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are tcs coding interviews?add

Based on 100 reported problems, tcs interviews are easier than average - only 5% Hard compared to 18% across all companies. 45% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a tcs coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, string, math. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your tcs interview?

Simulate a real tcs coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a tcs interview with AIarrow_forward