TCS interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

TCS
upvote
share-icon
2 rounds | 10 Coding problems

Interview preparation journey

expand-icon
Journey
I learned about this opportunity from a WhatsApp group and coding ninjas; the mentors helped me a lot in preparation. Moreover, the resume reviews and the mock interview also helped a lot.
Application story
I learned about this opportunity from a WhatsApp group. I applied for the job immediately and started practicing the questions.
Why selected/rejected for the role?
I was rejected in the Web Development round as the interviewer asked me to do a small project, and I could not do the project in the time given by the interviewer.
Preparation
Duration: 3 months
Topics: Data structures , Web design , HTML, CSS , Javascript , System design
Tip
Tip

Tip 1: Practice at least 300 questions from different topics and of varying difficulty levels by completing a data sheet. 

Tip 2: Do small projects on every concept, and in the end, when you have completed a particular technology, try doing a project on it. 

Tip 3: Last but not least, give mock interviews before the actual consultation.

Application process
Where: Other
Resume Tip
Resume tip

Tip 1: Link your portfolio website in the resume and add all the live links of the projects on the portfolio website.
Tip 2: Please use editors like Overleaf to make your resume.

Interview rounds

01
Round
Easy
Online Coding Interview
Duration150 minutes
Interview date26 Feb 2022
Coding problem5

Timing: 2:00 PM to 4:30 PM afternoon
Environment: Average

1. Puzzle

Four men could check some exam papers in 8 days, working 5 hours regularly. What are the hours two men take in 20 days to double the number of exam papers?

Problem approach

Assuming that 1 unit of work is done in 1 hour, calculate the total working hours: => 4 * 8 * 5 = 160 units. Now the work is doubled: => 160 * 2 = 320 units. Let ‘x’ be the number of hours two job men take to complete the work in 20 days. Therefore, => 2 * 20 * x = 320 => x = 8 hours (Answer).

2. Aptitude

If f(x) = ax^4 – bx^2 + x + 5 and given f(-3) = 2, then f(3) = ? (a^b = a raised to power b)
a) 3
b) 8
c) 1
d) -2

Problem approach

We can directly solve:
=> f(-3) = a(-3)^4 – b(-3)^2 + (-3) + 5 = 2
=> 81a – 9b + 2 = 2
=> 81a – 9b = 0
Now solving f(3),
=> f(3) = 81a – 9b + 8
=> f(3) = 0 + 8 = 8(Answer)

3. Puzzle

Ram appears for an exam. In paper A, he scores 18 out of 70. In paper B, he scores 14 out of 30. So, in which paper did he perform better?
a) Paper A
b) Paper B

Problem approach

We just need to calculate the percentage he scored in each paper.
In paper A: (18/70) * 100 = 25.7%
In paper B: (14/30) * 100 = 46.6% (Answer)

4. Minimum operation needed to convert to the given string

Moderate
26m average time
0/80
Asked in companies
SamsungAppleMicrosoft

You are given two strings 'str1' and 'str2'. Find the minimum operations required to convert str1 into str2.

An Operation is defined as:
A character from an index of a string(str1) is put at the end of it, is defined as a single operation.
 Note :
You cannot perform any operation on the string, str2.
Problem approach

Approach: The problem can be solved using Hashing. Follow the steps below to solve the problem:

Initialize a 2D array, say hash[][], where hash[i][j] stores the frequency of the character i present at the jth index of all the strings.
Traverse the array arr[] using variable i. For every ith string encountered, count the frequency of each distinct character of the string and store it into the hash[][] array.
Initialize a variable, say cntMinOp, to store the minimum count of operations required to make all the strings of the array equal.
Traverse the array hash[][] using variable i. For every ith column encountered, calculate the sum of the column, say Sum, the maximum element in the column, say Max, and update cntMinOp += (Sum – Max).
Finally, print the value of cntMinOp.


Code : // Function to find the minimum count of
// operations required to make all Strings
// equal by replacing characters of Strings
static int minOperation(String arr[], int N)
{

// Stores minimum count of operations
// required to make all Strings equal
int cntMinOP = 0;

// Stores length of the String
int M = arr[0].length();

// hash[i][j]: Stores frequency of character
// i present at j-th index of all Strings
int [][]hash = new int[256][M];


// Traverse the array arr[]
for (int i = 0; i < N; i++) 
{

// Iterate over characters of
// current String
for (int j = 0; j < M; j++) 
{

// Update frequency of
// arr[i][j]
hash[arr[i].charAt(j)][j]++;
}
}

// Traverse hash[][] array
for (int i = 0; i < M; i++)
{

// Stores sum of i-th column
int Sum = 0;

// Stores the largest element
// of i-th column
int Max = 0;

// Iterate over all possible
// characters
for (int j = 0; j < 256; j++) 
{

// Update Sum
Sum += hash[j][i];

// Update Max
Max = Math.max(Max, hash[j][i]);
}

// Update cntMinOP
cntMinOP += (Sum - Max);
}

return cntMinOP;
}

Try solving now

5. Sorted Matrix

Moderate
25m average time
85% success
0/80
Asked in companies
MicrosoftAmazonFidelity International

You are given an N x N matrix 'MAT' of positive integers, where every row and column is sorted in non-decreasing order.

Your task is to return a list containing all elements of the matrix in sorted order.

For example :

If the matrix is:

10 20 30 40
15 20 35 42
27 29 37 46
32 33 38 49

The output will be the elements of matrix in sorted order:
10 15 20 20 27 29 30 32 33 35 37 38 40 42 46 49

Follow Up:

Can you solve this in O((N ^ 2) * log(N)) time and O(N) space complexity?
Try solving now
02
Round
Easy
Video Call
Duration30 minutes
Interview date25 Mar 2022
Coding problem5

Timing: 2:00 PM to 2:30 PM Afternoon
The environment was relaxed. The interviewer was a nice and humble guy.

1. Theory Questions

What is Constructor? (Learn)

Problem approach
  • Constructor is a special method that is called when an object is created.
  • It has the same name as the class it belongs to
  • It can take parameters to initialize the object's properties
  • It can be overloaded to have multiple constructors with different parameters

2. Theory Questions

Explain Token generation and authentication process. (Learn)

Problem approach

The token generation and authentication process are a security mechanism used to verify the identity of a user.
Token generation involves creating a unique token for each user upon successful login.
The token is then stored in the user's browser or device.
When the user makes subsequent requests, the token is sent along with the request.
The server then verifies the token to authenticate the user.
The user is granted access to the requested resource if the token is valid.
Examples of token-based authentication include OAuth and JSON Web Tokens (JWT).

3. Theory Questions

Explain any one of design patterns with examples. (Learn)

Problem approach

One of the design patterns is the Singleton pattern.
Singleton pattern ensures that only one class instance is created and provides a global point of access to it.
It is helpful to limit the number of class instances to one.
Example: Database connection class, where we need only one instance class instance to the database.
Another example is the Logger class, where we need only one instance to log messages throughout the application.

4. Development Problem

Create a popup box using HTML, CSS, and JS. (Learn)

Problem approach

Approach 1:  when clicked approach. This will show how to create a popup box or window using HTML and CSS. We use basic HTML tags like heading, paragraph, button, and anchor tags. As seen in the output, we make a buttonThisked, and the popup box will open. The anchor element is attached to the popup box with the “modal” class by using the href attribute to specify a link to the “popup-box” address."

The original sentence does not contain any grammatical errors. The term "buttonThisked" appears to be a typo or a placeholder, but it was not identified as a grammatical error. If "buttonThisked" is incorrect, please clarify or provide the correct term.







.box {
background-color: black;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
p {
font-size: 17px;
align-items: center;
}
.box a {
display: inline-block;
background-color: #fff;
padding: 15px;
border-radius: 3px;
}
.modal {
align-items: center;
display: flex;
justify-content: center; 
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(254, 126, 126, 0.7);
transition: all 0.4s;
visibility: hidden;
opacity: 0;
}
.content {
position: absolute;
background: white;
width: 400px;
padding: 1em 2em;
border-radius: 4px;

.modal: target {
visibility: visible;
opacity: 1;
}
.box-close {
position: absolute;
top: 0;
right: 15px;
color: #fe0606;
text-decoration: none;
font-size: 30px;
}





Click to Open the pop-up box!





×




 

5. Development Questions

Center an element horizontally and vertically using html and css.(Learn)

Problem approach

There are several ways to center an element both horizontally and vertically on a web page, but the most common approach is to use CSS. There are a few methods using CSS:

Using HTML table 
Using flexbox 
Using grid 
Using position and transform
Using JavaScript

Approach 1: To center an element both horizontally and vertically, you can use the HTML element as follows.




Test
Center an element horizontally and vertically 





Hello World!








Approach 2: Using flexbox: Set the display property of the parent element to “flex” and set the justify-content and align-items properties to “center”. 

Flexbox: It is a layout mode in CSS that is used to align and distribute space among items in a container. It is a one-dimensional layout and is used to align elements either horizontally or vertically.
justify-content: It is a CSS property used in Flexbox that defines how the browser distributes free space between and around content items along the main axis of the container.
align-items: It is a CSS property used in Flexbox that defines how the browser distributes free space between and around content items along the cross-axis of the container.






Centering an element using Flexbox


.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
/* Set the height of the container to the viewport height */
}
.element {
background-color: #308D46;
padding: 20px;
color: #fff;
}





Test





Approach 3: Using Grid: Set the display property of the parent element to “grid” and use the “place-items“ property to center the child element. For example:

grid: It is a layout mode in CSS that is used to align and distribute space among items in a container. It is a two-dimensional layout and is used to align elements both horizontally and vertically.
place-items: It is a CSS property used in the grid that sets both the align-items and justify-items properties of the grid items in a container.






.container {
display: grid;
/* set height of the container to the viewport height */
height: 100vh;
/* to center the grid items both horizontally and vertically */
place-items: center;
}
.element {
background-color: #308D46;
padding: 20px;
color: #fff;
}





TCS





Approach 4: Using position and transform: Set the position property of the child element to “absolute” and use the transform property to translate the element to the center of the parent element. For example:

absolute: It is a value of the position property used in CSS which takes an element out of the normal document flow and positions it relative to the nearest positioned ancestor.
transform: It is a CSS property used to modify the appearance of an element. In the context of centering, the translate() function of the transform property is used to move an element horizontally and vertically.





Centering an element using Flexbox

.element {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #308D46;
padding: 20px;
color: white;
}





Test





Approach 5: Using JavaScript: You can center an element both horizontally and vertically using JavaScript by setting its position to “absolute”, and then calculating its top and left properties using the window’s dimensions and the element’s dimensions. 

Example: We first get the element we want to center using document.getElementById(). We then get its width and height using the offsetWidth and offsetHeight properties. We also get the window’s width and height using window.innerWidth and window.innerHeight.

We then set the element’s position to “absolute”. This allows us to position it anywhere on the page.

We calculate the top property by subtracting the element’s height from the window’s height and then dividing by 2. We calculate the left property in a similar way, by subtracting the element’s width from the window’s width, and then dividing by 2. Finally, we set the top and left properties of the element using template literals and the style property.




Center Element with JavaScript

#element {
width: 250px;
height: 100px;
background-color: green;
color: #fff;
text-align: center;
line-height: 100px;
font-size: 24px;
}




TEST


const elem = document.getElementById('element');
const elemWidth = elem.offsetWidth;
const elemHeight = elem.offsetHeight;
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;

elem.style.position = 'absolute';
elem.style.top = `${(windowHeight - elemHeight) / 2}px`;
elem.style.left = `${(windowWidth - elemWidth) / 2}px`;


 

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

How do you remove whitespace from the start of a string?

Choose another skill to practice
Similar interview experiences
SDE - 1
3 rounds | 6 problems
Interviewed by TCS
1607 views
0 comments
0 upvotes
SDE - 1
2 rounds | 4 problems
Interviewed by TCS
0 views
0 comments
0 upvotes
SDE - 1
2 rounds | 2 problems
Interviewed by TCS
1115 views
0 comments
0 upvotes
SDE - 1
2 rounds | 3 problems
Interviewed by TCS
1260 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
115096 views
24 comments
0 upvotes
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
58237 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35146 views
7 comments
0 upvotes