Plivo
TCS Interview Questions and Answers
Q1. Given an array of 0s, 1s and 2s sort the array - expected O(n)
Sort an array of 0s, 1s, and 2s in O(n) time complexity.
Use three pointers to keep track of the positions of 0s, 1s, and 2s.
Traverse the array and swap elements to their respective positions.
The first pointer should point to the first occurrence of 1, and the second pointer should point to the first occurrence of 2.
Example: [0, 1, 2, 0, 1, 2] -> [0, 0, 1, 1, 2, 2]
Q2. Given an array of 0s,1s and 2s sort the array - O(n)
Sort an array of 0s, 1s, and 2s in O(n) time complexity.
Use three pointers to keep track of the positions of 0s, 1s, and 2s.
Traverse the array and swap elements to their respective positions.
Time complexity is O(n) and space complexity is O(1).
Q3. Reverse a string and maintain the special character and space positions
Reverse a string while preserving the positions of special characters and spaces.
Iterate through the string from both ends using two pointers
Swap characters if both are alphabets or both are special characters
Continue until the pointers meet in the middle
Q4. write a program to determine if given strings are an anagram
A program to determine if given strings are an anagram.
Convert each string to lowercase and remove any non-alphabetic characters.
Sort the characters in each string.
Compare the sorted strings to check if they are equal.
Q5. Design tinyURL
Design a service to shorten long URLs into short ones.
Generate a unique ID for each long URL and store it in a database.
Map the unique ID to the long URL and store it in the database.
Create a short URL by using the unique ID as a parameter.
Redirect the short URL to the long URL when accessed.
Implement security measures to prevent abuse and ensure privacy.
Consider implementing analytics to track usage and performance.
Q6. Explain portfolio project
A portfolio project is a collection of work samples showcasing a designer's skills and experience.
Include a variety of projects to demonstrate range and expertise
Provide context for each project, explaining the problem, solution, and outcome
Highlight any special techniques or tools used in the projects
Showcase projects that align with the specific role or industry
Interview Process at TCS
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month