Tata Consultancy Services (TCS) is an Indian multinational information technology (IT) services and consulting company with its headquarters in Mumbai. It is a part of the Tata Group and operates in 149 locations across 46 countries. In July 2022, it was reported that TCS had crossed 6 lakh or 600,000 Employees worldwide.
It has got a 3.9* rating on Glassdoor and is considered one of the best service-based companies. It is highly regarded for its work-life balance.
They provide good training as well which will be beneficial in future too. You can practice the below questions collected from TCS Interview Experience for the interview. We have collected past frequently asked questions from TCS Interview Experience for your reference.
Categories of Questions
TCS Array Questions
Question 1. Coin Change 2 Leetcode Solution Problem Statement The Coin Change 2 LeetCode Solution – “Coin Change 2” states that given an array of distinct integers coins and an integer amount, representing a total amount of money. We need to return the count of the total number of different possible combinations that sum to the amount. ...
Question 2. Move all negative elements to one side of array Move all negative elements to one side of array – Suppose you have an array of integers. It consists of both negative and positive numbers and the problem statement asks to shift/move all the negative and positive elements to the left of the array and to the right of the ...
Question 3. Subarray with 0 sum The problem “Find if there is a subarray with 0 sum” states that you are given an integer array containing negative integers as well. The problem statement asks to determine if any sub-array of size at-least 1. This sub-array should have a sum equal to 1. Example arr[] = {2,1,-3,4,5} ...
Question 4. Stock Buy Sell to Maximize Profit Problem Statement In the “Stock Buy Sell to Maximize Profit” problem we have given an array that contains stock price on each day, find the maximum profit that you can make by buying and selling in those days. Here, we can buy and sell multiple times but only after selling ...
Question 5. Print All Distinct Elements of the Array Problem Statement We have an array of containing N integers which may be positive or negative. We have to print all distinct elements of the array. In other words, we can say that if a number occurs more than one time then we print only that number once. Example Input ...
Question 6. Find the First and Second Smallest Elements Problem Statement In find the first and second smallest elements problem we have given an array of integers. Find the first and second smallest integers from an array or find two smallest numbers from an array. Example Input 7, 6, 8, 10, 11, 5, 13, 99 Output First Smallest is ...
Question 7. Find the Number Occurring Odd Number of Times in an Array Problem Statement Given an array of positive integers. All numbers occur even a number of times except one number which occurs an odd number of times. We have to find the number occurring an odd number of times in an array. Example Input 1, 1, 1, 1, 2, 2, 3, ...
TCS String Questions
Question 8. Valid Parentheses Leetcode Solution Problem Statement The Valid Parentheses LeetCode Solution – “Valid Parentheses” states that you’re given a string containing just the characters '(', ')', '{', '}', '[' and ']'. We need to determine whether the input string is a valid string or not. A string is said to be a valid string if open brackets must be closed ...
Question 9. Reverse a String Problem Statement “Reverse a String” problem states that you are given a string s of size n. Write a program to reverse it. So, what does reversing a string means? It generally means reversing the input string that we are given. That is it is defined as an operation doing ...
Question 10. Identify and Mark Unmatched Parenthesis in an Expression In identify and mark unmatched parenthesis in an expression problem, we have given a string s of length n containing an expression. Find the balanced pair of parenthesis and replace all the balanced opening parenthesis as 0, the balanced closing parenthesis as 1 and the unbalanced parenthesis as -1. Example ...
Question 11. Remove Extra Spaces from a String Problem Statement In the “Remove Extra Spaces from a String” problem we have given a string “s”. Write a program to remove all extra_spaces from the given string. Input Format The first and only one line containing a string s with some spaces. Output Format Print a string after removing ...
Question 12. Removing Spaces from a String using stringstream Problem Statement In the “Removing Spaces from a String using stringstream” problem we have given a string “s”. Write a program that uses a string stream to remove spaces from the given string. Input Format The first and only one line containing a sentence/string “s”. Output Format The first line ...
TCS Tree Questions
Question 13. BFS vs DFS for Binary Tree Breadth First Search (BFS) Do we already know about what actually BFS is? if not then don’t need to feel bad just read the whole article and visit our previous article on Breadth First Search for better understanding. BFS is a level order traversal in which we visit the nodes of ...
TCS Stack Questions
Question 14. Valid Parentheses Leetcode Solution Problem Statement The Valid Parentheses LeetCode Solution – “Valid Parentheses” states that you’re given a string containing just the characters '(', ')', '{', '}', '[' and ']'. We need to determine whether the input string is a valid string or not. A string is said to be a valid string if open brackets must be closed ...
Question 15. Identify and Mark Unmatched Parenthesis in an Expression In identify and mark unmatched parenthesis in an expression problem, we have given a string s of length n containing an expression. Find the balanced pair of parenthesis and replace all the balanced opening parenthesis as 0, the balanced closing parenthesis as 1 and the unbalanced parenthesis as -1. Example ...
TCS Other Questions
Question 16. Binary Search LeetCode Solution Problem Statement Binary Search LeetCode Solution says that – 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 return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [-1,0,3,5,9,12], target ...
Question 17. Next Permutation LeetCode Solution Problem Statement Next Permutation LeetCode Solution – A permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following are considered permutations of arr: [1,2,3], [1,3,2], [3,1,2], [2,3,1]. The next permutation of an array of integers is the next lexicographically greater permutation of ...
Question 18. Palindrome Number LeetCode Solution Problem Statement Palindrome Number LeetCode Solution says that – Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right ...
Question 19. First Unique Character in a String LeetCode Solution Problem Statement First Unique Character in a String LeetCode Solution – Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example Test Case 1: Input: s = “leetcode” Output: 0 Test Case 2: Input: s = “aabb” Output: -1 Explanation ...
Question 20. Largest Rectangle in Histogram LeetCode Solution Problem Statement Largest Rectangle in Histogram LeetCode Solution – 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 histogram. Example Test Case 1: Input: heights = [2, 1, 5, 6, 2, 3] Output: 10 Explanation: ...
Question 21. Integer Break LeetCode Solution Problem Statement Integer Break LeetCode Solution – Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. We need to Return the maximum product we can get. Input: n = 2 Output: 1 Explanation: 2 = 1 + 1, ...
Question 22. Move Zeroes LeetCode Solution Problem Statement The problem, Move Zeroes LeetCode Solution states that you are given an array containing zero and non-zero elements and you need to move all the zeroes to the end of the array, maintaining the relative order of non-zero elements in the array. You also need to implement an in-place ...
Question 23. Single Number Leetcode Solution Problem Statement Single Number Leetcode Solution – We are given a non-empty array of integers and need to find an element that appears exactly once. It is given in the question that every element appears twice except for one. Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: ...
Question 24. Count items common to both the lists but with different prices Problem Statement You are given two lists. Each of which index contains the name of the item and its price. The problem statement asks to count items common to both the lists but with different prices, which is to find out how many numbers of items are common in both ...
Question 25. Special Number What can be so special about a number? Let us find out. We have with us an array of N numbers. A number can be special if it is divisible by one or more numbers except for the number itself. Firstly let us clear this with a few examples before ...
Question 26. GCD Of Two Numbers What is Greatest Common Factor? GCD of two numbers is the largest number that divides both of them. Approach-1 Brute Force Finding all the prime factors of both the numbers, then finding the product of the intersection. Finding the largest number that divides both the numbers. What is it that ...