Practo
50+ TCS Interview Questions and Answers
Q1. Intersection of Two Unsorted Arrays Problem Statement
Given two integer arrays ARR1
and ARR2
of sizes 'N' and 'M' respectively, find the intersection of these arrays. The intersection is defined as the set of e...read more
Find the intersection of two unsorted arrays while maintaining the order of elements from the first array.
Iterate through the elements of the first array and check if they exist in the second array.
Use a hash set to keep track of elements already seen in the second array for efficient lookup.
Maintain the order of elements from the first array while finding the intersection.
Handle duplicate elements in both arrays appropriately.
Output the intersection elements in the order the...read more
Q2. Rotting Oranges Problem Statement
You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:
- 0 - representing an empty cell
- 1 - representing a fresh orange...read more
Find the minimum time required to rot all fresh oranges adjacent to rotten oranges.
Create a queue to store the coordinates of rotten oranges and perform BFS to rot adjacent fresh oranges.
Track the time taken to rot all fresh oranges and return -1 if not all fresh oranges can be rotten.
Update the grid with the new state of oranges after each second.
Handle edge cases such as empty grid or no fresh oranges present.
Example: For the given grid, the minimum time required is 4 secon...read more
Q3. Power of 2 Problem Statement
Determine if it is possible to reorder the digits of a given integer 'N' such that the resulting number is a power of two. The leading digit must not be zero.
Input:
The first line ...read more
The problem involves determining if it is possible to reorder the digits of a given integer to form a power of 2.
Iterate through all possible permutations of the digits of the given integer.
Check if any of the permutations form a power of 2.
Return 1 if a valid permutation is found, else return 0.
Q4. Palindrome Linked List Problem Statement
You are provided with a singly linked list of integers. Your task is to determine whether the given singly linked list is a palindrome. Return true
if it is a palindrome...read more
Check if a given singly linked list is a palindrome or not.
Traverse the linked list to find the middle element using slow and fast pointers.
Reverse the second half of the linked list.
Compare the first half with the reversed second half to determine if it's a palindrome.
Q5. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
The task is to determine the total number of ways to make change for a specified value using given denominations.
Create a function that takes in the number of denominations, the denominations array, and the value to make change for as input
Use dynamic programming to iterate through all possible combinations of coins to make the specified value
Keep track of the number of ways to make change for each value from 0 to the target value
Return the total number of ways to make change...read more
Q6. Binary Tree Diameter Problem Statement
You are given a Binary Tree, and you need to determine the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any ...read more
The task is to find the diameter of a binary tree, which is the length of the longest path between any two end nodes in the tree.
Traverse the tree to find the longest path between two nodes.
Keep track of the maximum diameter found during traversal.
The diameter may not necessarily pass through the root node.
Consider both left and right subtrees while calculating the diameter.
Example: For input 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the diameter is 6.
Q7. Search Element in a Rotated Sorted Array
Given a sorted array that has been rotated, the task is to find the index of a specific element. The array is initially sorted in ascending order and then rotated clockw...read more
Search for an element in a rotated sorted array efficiently in O(logN) time complexity.
Implement binary search to find the pivot point where rotation occurs.
Divide the array into two subarrays and perform binary search on the appropriate subarray.
Handle cases where the element may be in the left or right subarray after rotation.
Return the index of the element if found, else return -1.
Q8. Check if Two Strings are Anagrams
Anagrams are words or names that can be formed by rearranging the letters of another word. For instance, 'spar' can be rearranged to form 'rasp', making them anagrams.
Explanat...read more
Check if two strings are anagrams by rearranging their letters.
Create a frequency map of characters for both strings
Compare the frequency maps to check if they are equal
Return True if the frequency maps are equal, else False
Q9. Balanced Parentheses Combinations
Given an integer N
representing the number of pairs of parentheses, find all the possible combinations of balanced parentheses using the given number of pairs.
Explanation:
Con...read more
Generate all possible combinations of balanced parentheses for a given number of pairs.
Use recursion to generate all possible combinations of balanced parentheses.
Keep track of the number of open and close parentheses used in each combination.
Return the valid combinations as an array of strings.
Q10. Queue Using Stacks Implementation
Design a queue data structure following the FIFO (First In First Out) principle using only stack instances.
Explanation:
Your task is to complete predefined functions to suppor...read more
Implement a queue using stacks following FIFO principle.
Use two stacks to simulate a queue.
For enQueue operation, push elements onto stack1.
For deQueue operation, if stack2 is empty, pop all elements from stack1 and push onto stack2, then pop from stack2.
For peek operation, if stack2 is empty, pop all elements from stack1 and push onto stack2, then return top of stack2.
For isEmpty operation, check if both stack1 and stack2 are empty.
Example: enQueue(5), enQueue(10), peek(), d...read more
Q11. Merge Intervals Problem Statement
You are provided with 'N' intervals, each containing two integers denoting the start time and end time of the interval.
Your task is to merge all overlapping intervals and retu...read more
Merge overlapping intervals and return sorted list of merged intervals by start time.
Sort the intervals based on start time.
Iterate through intervals and merge overlapping ones.
Return the merged intervals in sorted order.
There are multiple ways to display HTML elements, including inline, block, inline-block, and flex.
HTML elements can be displayed as inline, which allows them to flow with surrounding content.
Block elements take up the full width available and start on a new line.
Inline-block elements are displayed as blocks, but flow like inline elements.
Flexbox allows for more advanced layout options, such as aligning items and distributing space.
Q13. Longest Substring Without Repeating Characters Problem Statement
Given a string S
of length L
, determine the length of the longest substring that contains no repeating characters.
Example:
Input:
"abacb"
Output...read more
Find the length of the longest substring without repeating characters in a given string.
Use a sliding window approach to keep track of the longest substring without repeating characters.
Use a hashmap to store the index of each character in the string.
Update the start index of the window when a repeating character is encountered.
Calculate the maximum length of the substring as you iterate through the string.
Q14. 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
Calculate the total amount of rainwater that can be trapped between given elevations in an array.
Iterate through the array and calculate the maximum height on the left and right of each bar.
Calculate the amount of water that can be trapped at each bar by taking the minimum of the maximum heights on the left and right.
Sum up the trapped water at each bar to get the total trapped water for the entire array.
Q15. You have to write a function for dice which will return number from 1-6 with equal probability. constraints : you can not use random function, you can use only toss function
Function to simulate dice roll with equal probability without using random function
Use a toss function that returns either 0 or 1 with equal probability
Call the toss function 3 times and convert the result to a binary number
If the binary number is greater than 0 and less than or equal to 6, return it
If the binary number is greater than 6, repeat the process
Q16. Given three arrays sorted in non-decreasing order, print all common elements in these arrays. Examples: ar1[] = {1, 5, 10, 20, 40, 80} ar2[] = {6, 7, 20, 80, 100} ar3[] = {3, 4, 15, 20, 30, 70, 80, 120} Output:...
read moreGiven three sorted arrays, find common elements.
Create three pointers to traverse each array
Compare the elements at the pointers and move the pointer of the smallest element
If all pointers point to the same element, add it to the result and move all pointers
Repeat until any pointer reaches the end of its array
Q17. Given an array of integers which can be in one of four order – i.Increasing 2.Decreasing 3.decreasing then increasing 4.increasing then decreasing .Write a function to find the type of array
Function to determine the order of integers in an array.
Check first and last element to determine if increasing or decreasing
Check for inflection point to determine if order changes
Return order type as string
Q18. Design database schema for a movie site.Where user can watch the movie,genre of movie,give ratings and recommended movies to user.Also Write an algorithm to show recommended movies to user
Design a database schema for a movie site with user ratings and recommendations.
Create tables for movies, users, ratings, and recommendations
Use foreign keys to link tables
Include columns for movie genre and user watch history
Algorithm for recommendations can use user watch history and ratings to suggest similar movies
Access specifiers define the level of access to class members in Object-Oriented Programming.
Access specifiers include public, private, protected, and default
Public members are accessible from outside the class
Private members are only accessible within the class
Protected members are accessible within the class and its subclasses
Default access is when no access specifier is specified
Q20. Sudoku Solver Problem Statement
You are provided with a 9x9 sudoku grid. Your objective is to solve the sudoku and deliver the complete solution.
Description:
A sudoku puzzle is a 9x9 grid, divided into nine 3x...read more
Q21. Character Counting Program
Develop a program to calculate and display the total number of specific characters: lowercase English alphabets, digits (0 to 9), and white spaces (including space, tab '\t'
, and newl...read more
Optimizing website asset loading involves minimizing file sizes, reducing HTTP requests, utilizing caching, and prioritizing critical resources.
Minimize file sizes by compressing images, scripts, and stylesheets.
Reduce HTTP requests by combining files, using sprites, and lazy loading non-essential resources.
Utilize browser caching to store static assets locally for faster subsequent page loads.
Prioritize critical resources like above-the-fold content to ensure faster renderin...read more
Abstraction is hiding the implementation details while inheritance is a mechanism for creating new classes using existing classes.
Abstraction focuses on hiding the internal implementation details of a class, allowing the user to only interact with the necessary information.
Inheritance allows a class to inherit properties and behavior from another class, promoting code reusability and creating a hierarchy of classes.
Abstraction is achieved through abstract classes and interfac...read more
Fill the 5-liter jar, pour it into the 3-liter jar, fill the 5-liter jar again, and pour enough to fill the 3-liter jar. This leaves 4 liters in the 5-liter jar.
Fill the 5-liter jar
Pour the 5 liters into the 3-liter jar
Fill the 5-liter jar again
Pour enough to fill the 3-liter jar
4 liters will be left in the 5-liter jar
Advantages of OOP include code reusability, modularity, and easier maintenance.
Code reusability: Objects can be reused in different parts of the program, reducing redundancy.
Modularity: OOP allows for breaking down complex problems into smaller, more manageable parts.
Easier maintenance: Changes to one part of the codebase do not necessarily affect other parts, making maintenance easier.
Encapsulation: Data hiding and abstraction help in protecting data and only exposing necess...read more
Q26. Remove Vowels from String
Your task is to remove all the vowels from a given string STR
of length N
and return the modified string.
Explanation:
English alphabets 'a', 'e', 'i', 'o', 'u'
are termed as vowels. A...read more
Q27. Sliding Window Maximum
Given an array of integers with size N
and a number K
, your task is to determine the maximum value of each subarray of length K
from the array.
Input:
The first line contains two integers...read more
Q28. A puzzle. You will be given with a 3 Litre container & a 7 Litre Container. Measure exactly 5 Litres of water
Measure 5 litres of water using 3 and 7 litre containers.
Fill the 3 litre container completely
Pour the water from the 3 litre container into the 7 litre container
Fill the 3 litre container again and pour it into the 7 litre container until it is full
The remaining water in the 3 litre container is 1 litre
Empty the 7 litre container and pour the 1 litre water from the 3 litre container into it
Fill the 3 litre container again and pour it into the 7 litre container
The 7 litre con...read more
Q29. What do you know about hospital process for treatment?
Hospital process for treatment involves several steps from admission to discharge.
The patient is admitted to the hospital and undergoes initial assessment and diagnosis.
A treatment plan is created based on the diagnosis and the patient's medical history.
The patient is then treated with medication, surgery, or other procedures as necessary.
During the treatment, the patient's progress is monitored and adjustments are made to the treatment plan if needed.
Once the treatment is co...read more
Q30. What is left join. Give example. And Full outer join?
Left join returns all records from left table and matching records from right table. Full outer join returns all records from both tables.
Left join is used to combine two tables based on a common column.
In left join, all records from the left table are returned along with matching records from the right table.
If there is no match in the right table, NULL values are returned.
Example: SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;
Full outer join returns all rec...read more
Q31. How can you improve the performance of a site.(Only frontend)
Optimize images, minify code, reduce HTTP requests, use caching, and lazy loading.
Optimize images using compression and appropriate file formats
Minify code to reduce file size and improve load times
Reduce HTTP requests by combining files and using sprites
Use caching to store frequently accessed data locally
Implement lazy loading to defer loading of non-critical resources
Event bubbling is the process where an event triggered on a child element is propagated up through its parent elements.
In event bubbling, when an event occurs on a child element, it first runs the event handlers on the child element, then on its parent, then all the way up to the top level of the DOM.
Event bubbling allows for delegation of event handling to a parent element, reducing the number of event listeners needed.
To stop event bubbling, you can use the stopPropagation(...read more
Q33. What is magic functions and autoloading in PHP?
Magic functions are special methods in PHP that start with __. Autoloading is a way to automatically load classes.
Magic functions are used to handle certain events in PHP, such as object creation or property access.
Autoloading allows PHP to automatically load classes when they are needed, without requiring manual includes.
Magic functions can be used in conjunction with autoloading to dynamically load classes or handle errors.
A static variable in C is a variable that retains its value between function calls.
Declared using the 'static' keyword
Retains its value throughout the program's execution
Useful for maintaining state across function calls
Q35. Write a function to check if two strings are anagram or not
Function to check if two strings are anagram or not
Create two character arrays from the strings
Sort the arrays
Compare the sorted arrays
Q36. How do you sell a particular object and how do you promote that
To sell and promote a particular object, I focus on understanding the target audience, highlighting the unique features and benefits, and utilizing various marketing channels.
Research and understand the target audience and their needs
Highlight the unique features and benefits of the object
Utilize various marketing channels such as social media, email marketing, and advertising
Offer promotions or discounts to incentivize purchases
Provide excellent customer service to build tru...read more
Q37. Write a query to fetch duplicate email from table?
Query to fetch duplicate email from table
Use GROUP BY and HAVING clause to filter out duplicates
SELECT email, COUNT(*) FROM table_name GROUP BY email HAVING COUNT(*) > 1;
This will return all the duplicate emails in the table
Q38. What is IPD and OPD?
IPD stands for In-Patient Department and OPD stands for Out-Patient Department.
IPD refers to the hospital department where patients are admitted for overnight stay and treatment.
OPD refers to the hospital department where patients receive medical treatment and consultation without being admitted.
IPD is also known as the hospital's ward or inpatient care unit.
OPD is also known as the hospital's outpatient care unit.
IPD is usually for patients who require intensive care and mon...read more
Q39. Difference between .on(‘click’,function() and .click(function())
The .on('click',function() is a more flexible method than .click(function())
The .on() method can handle multiple events and selectors
The .click() method can only handle one event and one selector
The .on() method can also handle dynamically added elements
The .click() method cannot handle dynamically added elements
Q40. Implement queue with the help of two stacks
Queue can be implemented using two stacks by maintaining the order of elements in the stacks.
Create two stacks, let's call them stack1 and stack2
When an element is enqueued, push it to stack1
When an element is dequeued, pop all elements from stack1 and push them to stack2
Pop the top element from stack2 and return it as the dequeued element
If stack2 is empty, repeat step 3
To get the front element of the queue, peek the top element of stack2
Q41. Find if a number is a power of 2 or not?
Check if a number is a power of 2 or not.
A power of 2 has only one bit set in its binary representation.
Use bitwise AND operator to check if the number is a power of 2.
If n is a power of 2, then n & (n-1) will be 0.
Q42. What is event bubbling?
Event bubbling is the propagation of an event from the innermost child element to the outermost parent element.
Events triggered on a child element will also trigger on its parent elements
The event travels up the DOM tree until it reaches the document object
Can be stopped using event.stopPropagation()
Can be useful for event delegation
Q43. Design a video streaming app's search page
The search page of a video streaming app should allow users to easily search for and discover content.
Include a search bar at the top for users to enter keywords or phrases
Display relevant search results in a grid or list format
Provide filters or sorting options to refine search results
Include thumbnails, titles, and brief descriptions of the search results
Allow users to click on search results to view more details or start streaming
Q44. What you think most need qualites in sales
Qualities like communication, empathy, persistence, and adaptability are crucial in sales.
Effective communication skills to build relationships with clients
Empathy to understand the client's needs and provide tailored solutions
Persistence to follow up with clients and close deals
Adaptability to adjust to changing market trends and client demands
Q45. What is the therapeutic and pharmacological classification of Paracetamol
Q46. Find total number of unique palindromic sub sequences from a string.
Find total number of unique palindromic sub sequences from a string.
Use dynamic programming to find all palindromic sub sequences.
Store the count of each sub sequence in a hash table.
Return the count of unique sub sequences.
Q48. What is your expected ctc
My expected CTC is in line with industry standards and commensurate with my experience and skills.
My expected CTC is based on my current salary, industry standards, and the responsibilities of the role.
I am open to negotiation based on the overall compensation package, including benefits and incentives.
I am looking for a fair and competitive salary that reflects my experience and skills.
I have researched the market and have a realistic expectation for my expected CTC.
I am con...read more
Q49. Find if a number is a power of 2 or not.3
Check if a number is a power of 2 or not.
A power of 2 has only one bit set in its binary representation.
Use bitwise AND operator to check if the number is a power of 2.
If n is a power of 2, then n & (n-1) will be 0.
Examples: 2 (10), 4 (100), 8 (1000), 16 (10000), etc.
Examples: 3 (11), 5 (101), 7 (111), 9 (1001), etc.
Q50. Which company last experience 1 years
I don't have the available data
Q51. How to connect with clients
Connecting with clients requires active listening, clear communication, and building trust.
Listen actively to their concerns and needs
Communicate clearly and effectively, using language they understand
Build trust by being reliable, responsive, and transparent
Show empathy and understanding for their situation
Provide personalized solutions and follow-up support
Maintain regular communication to stay informed and address any issues
Ask for feedback and use it to improve the custom...read more
Q53. How do you scale a business
Scaling a business involves strategic planning, efficient resource allocation, and continuous growth.
Identify key growth opportunities and target markets
Invest in technology and automation to streamline processes
Build a strong team and delegate responsibilities effectively
Establish partnerships and collaborations to expand reach
Monitor performance metrics and adjust strategies accordingly
Q54. tell us about Data Structure .
Data structure is a way of organizing and storing data in a computer so that it can be accessed and used efficiently.
Data structures are used to manage and manipulate data.
They can be classified into linear and non-linear data structures.
Examples of linear data structures include arrays, linked lists, and stacks.
Examples of non-linear data structures include trees and graphs.
Choosing the right data structure is important for efficient data processing.
Q55. Find the median of two arrays
To find the median of two arrays, merge them and then find the middle element(s).
Merge the two arrays into a single sorted array
If the length of the merged array is odd, return the middle element
If the length of the merged array is even, return the average of the two middle elements
Q56. Merge two binary trees
Merge two binary trees by summing up the values of corresponding nodes
Traverse both trees simultaneously and sum up the values of corresponding nodes
If a node exists in only one tree, add it to the merged tree as is
Recursively merge the left and right subtrees
Q57. Design middleware for homepage
Design middleware to handle requests and responses for homepage
Identify the key functionalities needed for the homepage middleware
Implement caching mechanisms to improve performance
Ensure proper error handling and logging
Consider scalability and load balancing for high traffic
Integrate with analytics tools for tracking user behavior
Q58. Explain project
Developed a web application for tracking personal fitness goals and progress
Used HTML, CSS, and JavaScript for front-end development
Implemented a RESTful API using Node.js and Express for back-end functionality
Utilized MongoDB for database storage and retrieval
Incorporated user authentication and authorization using JWT tokens
Q59. list of array dbms
Array DBMS are databases that store data in arrays instead of traditional tables.
Some examples of array DBMS include MongoDB, Couchbase, and Cassandra.
Array DBMS are often used for storing unstructured data or data that can be easily represented as arrays.
They are known for their flexibility and scalability in handling large amounts of data.
More about working at Practo
Interview Process at TCS
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month