Unthinkable Solutions
30+ TCS Interview Questions and Answers
Q1. Find Duplicate in Array Problem Statement
You are provided with an array of integers 'ARR' consisting of 'N' elements. Each integer is within the range [1, N-1], and the array contains exactly one duplicated el...read more
The task is to find the duplicate element in an array of integers.
Iterate through the array and keep track of the frequency of each element using a hash map.
Return the element with a frequency greater than 1.
Alternatively, sort the array and check for adjacent elements with the same value.
Q2. Trapping Rain Water Problem Statement
You are given a long type array/list ARR
of size N
, representing an elevation map. The value ARR[i]
denotes the elevation of the ith
bar. Your task is to determine the tota...read more
The question asks to find the total amount of rainwater that can be trapped in the given elevation map.
Iterate through the array and find the maximum height on the left and right side of each bar.
Calculate the amount of water that can be trapped on each bar by subtracting its height from the minimum of the maximum heights on both sides.
Sum up the amount of water trapped on each bar to get the total amount of rainwater trapped.
Q3. Reverse String Word Wise Problem Statement
Your task is to reverse the given string word-wise. This means the last word in the string should appear first, the second last word should appear second, and so forth...read more
The given string needs to be reversed word wise, keeping the individual words intact.
Split the string into an array of words using a space as the delimiter.
Reverse the array of words.
Join the reversed array of words using a space as the separator to form the final reversed string.
Q4. Problem: Sort an Array of 0s, 1s, and 2s
Given an array/list ARR
consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.
Input:
The input starts with...read more
The task is to sort an array of 0s, 1s, and 2s in increasing order.
Use a three-pointer approach to partition the array into three sections: 0s, 1s, and 2s.
Initialize three pointers: low, mid, and high. low points to the start of the array, mid points to the current element being processed, and high points to the end of the array.
While mid <= high, perform the following checks: if arr[mid] == 0, swap arr[low] and arr[mid], increment low and mid. If arr[mid] == 1, increment mid...read more
Q5. Find the Second Largest Element
Given an array or list of integers 'ARR', identify the second largest element in 'ARR'.
If a second largest element does not exist, return -1.
Example:
Input:
ARR = [2, 4, 5, 6, ...read more
The task is to find the second largest element in an array of integers.
Iterate through the array and keep track of the largest and second largest elements.
Initialize the largest and second largest variables with the first two elements of the array.
Compare each element with the largest and second largest variables and update them accordingly.
Return the second largest element at the end.
Q6. Sort Array by Reversing a Subarray
You are given an array of 'N' distinct integers, 'ARR'. Determine if it is possible to sort this array by selecting a continuous subarray and reversing it. Return 'true' if so...read more
The question asks whether it is possible to sort an array by choosing a continuous subarray and reversing it.
Check if the array is already sorted. If yes, return true.
Find the first and last elements of the subarray that needs to be reversed.
Check if the subarray is in non-decreasing order. If yes, return true.
Check if the elements after the subarray are in non-increasing order. If yes, return true.
Otherwise, return false.
Q7. Kth Largest Number Problem Statement
Design a data structure to process a stream of numbers and efficiently find the kth largest number at any given point in time.
Explanation:
You will receive a continuous str...read more
Design a data structure to efficiently find the kth largest number in a stream of numbers.
Implement a data structure that can store incoming numbers and efficiently retrieve the kth largest number.
Support addition of numbers and retrieval of the kth largest number.
Use a priority queue or heap data structure to maintain the k largest numbers in the stream.
Handle queries of adding numbers and retrieving the kth largest number.
Ensure the system can handle an indefinite length of...read more
Q8. Binary Search Tree Search Problem
Given a Binary Search Tree (BST) consisting of 'N' nodes, where each node contains some integer data, your task is to determine whether there is a node in the BST whose data is...read more
Given a Binary Search Tree, determine if a node with a given integer exists.
Traverse the BST in a way that compares the current node's data with the given integer 'X'.
If the current node's data is equal to 'X', return True.
If the current node's data is less than 'X', move to the right subtree; if greater, move to the left subtree.
Repeat this process until a match is found or the end of the tree is reached.
Q9. 1) coding question range is given example 2 to 10 in this range find 3 largest prime number sum. and for this 2 to 10 range exmaple is 3, 5 , 7 sum=15.
Find the sum of three largest prime numbers within a given range.
Create a function to check if a number is prime.
Loop through the given range and store prime numbers in an array.
Sort the array in descending order and sum the first three elements.
Return the sum.
Q10. Remove Duplicates Problem Statement
You are given an array of integers. The task is to remove all duplicate elements and return the array while maintaining the order in which the elements were provided.
Example...read more
Remove duplicates from an array while maintaining order.
Use a set to keep track of unique elements.
Iterate through the array and add elements to the set if not already present.
Convert the set back to an array to maintain order.
Q11. How would you design a store management system, including all relevant schema tables?
Design a store management system with relevant schema tables
Create a 'Store' table with attributes like store_id, name, location, etc.
Design a 'Product' table with attributes like product_id, name, price, quantity, etc.
Include a 'Sales' table to track sales transactions with attributes like sale_id, date, total_amount, etc.
Implement a 'Stock' table to manage product stock levels with attributes like stock_id, product_id, quantity_available, etc.
Q12. Implement debouncing, create a nodejs server with a get / post api, a puzzle, javascript questions like clousers, let / var / const, event loop, output based questions etc.
Implement debouncing, create a nodejs server with get/post api, and answer JavaScript questions.
Implement debouncing by using setTimeout and clearTimeout to limit the number of times a function is called.
Create a nodejs server with Express framework to handle get and post requests.
Answer JavaScript questions on closures, let/var/const, event loop, and output based questions.
Provide examples for each concept to demonstrate understanding.
Q13. Design category schema where category can have multiple sub categories
Design a category schema with multiple subcategories
Use a parent-child relationship to link categories and subcategories
Implement a tree data structure to represent the hierarchy
Each category can have multiple subcategories
Example: Category - Electronics, Subcategories - Computers, Mobile Phones, TVs
Q14. Write code for searching in a 2D matrix with a time complexity of O(mlogn)?
Implement a binary search in each row of a sorted 2D matrix to achieve O(mlogn) time complexity.
Divide and conquer approach can be used to search in each row of the matrix.
Perform binary search on each row to find the target element efficiently.
Ensure the rows are sorted to apply binary search in each row.
Q15. SQL query to find second highest salary
SQL query to find second highest salary
Use the ORDER BY clause to sort salaries in descending order
Use the LIMIT clause to retrieve the second row
Q16. what is SANITY , Smoke Testing. Explain difference giving live project examples.
Sanity and Smoke Testing are types of software testing used to ensure the stability of the application.
Smoke Testing is a quick and shallow test to check if the application is stable enough for further testing.
Sanity Testing is a more thorough test to check if the application is ready for release.
Smoke Testing is usually done after a new build is released, while Sanity Testing is done after major changes are made to the application.
Example of Smoke Testing: Checking if the lo...read more
Q17. Sql queries which consists of group and joins
SQL queries involving group by and joins are used to retrieve data from multiple tables and aggregate results.
Use GROUP BY to group rows that have the same values in specified columns
Use JOIN to combine rows from two or more tables based on a related column
Examples: SELECT column1, SUM(column2) FROM table1 JOIN table2 ON table1.id = table2.id GROUP BY column1
Q18. What is difference between integration and System testing.
Integration testing checks if different modules work together, while system testing checks if the entire system meets requirements.
Integration testing focuses on testing the interfaces between modules or components of a system.
System testing focuses on testing the entire system as a whole, including all integrated components.
Integration testing is performed before system testing.
System testing is performed after integration testing.
Integration testing is usually done by devel...read more
Q19. Star pattern in C language
Star pattern is a common programming exercise to print a pattern of stars in a specific shape.
Use nested loops to print the desired number of rows and columns.
Use if-else statements to determine when to print a star or a space.
Experiment with different loop conditions and print statements to create different patterns.
Q20. Write a sql query to join two tables and find some data from one table.
SQL query to join two tables and retrieve data from one table.
Use JOIN keyword to combine tables based on a related column
Specify the columns to retrieve using SELECT statement
Add conditions using WHERE clause if needed
Q21. Designing dbms for a college website
Designing a DBMS for a college website involves creating tables for students, courses, faculty, and more.
Create tables for students, courses, faculty, departments, etc.
Establish relationships between tables using foreign keys.
Include attributes like student ID, course ID, faculty ID, etc.
Implement normalization to reduce redundancy and improve data integrity.
Consider implementing views for complex queries or reports.
Q22. How JS works and nodeJs works
JavaScript is a scripting language used for web development, while Node.js is a runtime environment that allows JavaScript to run on the server side.
JavaScript is a client-side scripting language used for creating interactive web pages.
Node.js is a runtime environment that allows JavaScript to run on the server side.
Node.js uses the V8 JavaScript engine from Google Chrome to execute code.
Node.js provides a set of built-in modules that help in building server-side applications...read more
Q23. What are Joins?
Joins are used in databases to combine rows from two or more tables based on a related column between them.
Joins are used to retrieve data from multiple tables based on a related column.
Common types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
INNER JOIN returns rows when there is at least one match in both tables.
LEFT JOIN returns all rows from the left table and the matched rows from the right table.
RIGHT JOIN returns all rows from the right table and t...read more
Q24. Design schema of your project
The schema of my project is designed to efficiently store and retrieve data for a web application.
Use relational database to store structured data
Create tables for different entities like users, products, orders
Establish relationships between tables using foreign keys
Use indexes to optimize query performance
Q25. What is Agile .Explain
Agile is a project management methodology that emphasizes on iterative development, collaboration, and customer satisfaction.
Agile is based on the Agile Manifesto, which values individuals and interactions, working software, customer collaboration, and responding to change.
Agile involves breaking down a project into smaller, manageable chunks called sprints.
Agile encourages continuous feedback and improvement throughout the development process.
Examples of Agile methodologies ...read more
Q26. 1)Largest Area of Histogram
The largest area of a histogram is the maximum area that can be enclosed by a rectangle within the histogram bars.
Calculate the largest area of a histogram by finding the maximum area of rectangles that can be formed within the histogram bars.
This can be done by iterating through each bar and calculating the area of rectangles that can be formed with that bar as the height.
Keep track of the maximum area found so far and return it as the largest area of the histogram.
Q27. minimum effort in an array
Find the string with minimum length in an array of strings.
Iterate through the array and keep track of the minimum length string
Return the string with the minimum length
Q28. Tell about Technical Skills
I have strong technical skills in test automation, manual testing, bug tracking, and test case design.
Proficient in test automation tools like Selenium and JUnit
Skilled in manual testing techniques and methodologies
Experience with bug tracking systems such as Jira
Ability to design comprehensive test cases for various scenarios
Q29. String reverse code in any language
Reverse a string in any programming language
Use a loop to iterate through the characters of the string
Swap the characters from start to end of the string
Repeat until the entire string is reversed
Q30. Reverse a linked list.
Reverse a linked list by changing the pointers direction.
Start with three pointers: current, previous, and next.
Iterate through the linked list, updating the pointers to reverse the direction.
Update the head of the linked list to be the previous node once the end is reached.
Q31. Find loop in linked list
Use Floyd's Tortoise and Hare algorithm to find a loop in a linked list.
Initialize two pointers, slow and fast, at the head of the linked list.
Move slow pointer by one step and fast pointer by two steps.
If they meet at some point, there is a loop in the linked list.
Q32. Longest common substring
Finding the longest common substring among a set of strings.
Iterate through all substrings of the first string and check if they are present in all other strings.
Keep track of the longest common substring found so far.
Return the longest common substring.
Q33. sum without plus sign
Use bitwise operators to perform addition without using the plus sign.
Use bitwise XOR operation to add two numbers without carrying over
Use bitwise AND operation to find the carry bits and shift them to the left
Repeat the process until there are no more carry bits
Q34. Largest Area of Histogram
The largest area of a histogram can be found by calculating the maximum area of rectangles formed by the histogram bars.
Calculate the area of rectangles formed by each bar and find the maximum area.
Consider the width of the rectangle as the number of consecutive bars with height greater than or equal to the current bar.
Example: For histogram [2,1,5,6,2,3], the largest area would be 10 (5*2).
Q35. Define Constructors
Constructors are special methods in a class that are used to initialize objects.
Constructors have the same name as the class they belong to.
They are called automatically when an object of the class is created.
Constructors can have parameters to initialize the object with specific values.
Example: public class Car { public Car(String color) { this.color = color; }}
Q36. Define Oops pillars
Oops pillars refer to the four main concepts of object-oriented programming: Inheritance, Encapsulation, Polymorphism, and Abstraction.
Inheritance: Allows a class to inherit properties and behavior from another class.
Encapsulation: Bundling data and methods that operate on the data into a single unit.
Polymorphism: Ability of a function to behave differently based on the object it is acting upon.
Abstraction: Hiding the complex implementation details and showing only the necess...read more
Q37. reverse the string
Reverse a given string
Use a loop to iterate through the characters of the string and build a new string in reverse order
Alternatively, use built-in functions like reverse() or StringBuilder in some programming languages
Top HR Questions asked in TCS
Interview Process at TCS
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month