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

SDE - 1

Microsoft
upvote
share-icon
2 rounds | 4 Coding problems

Interview preparation journey

expand-icon
Journey
I applied for the role through the on-campus placement portal at IIT Guwahati. My journey began in August, with a strong focus on DSA and core computer science subjects. The process started with a rigorous online assessment (OA), which included sections on coding, math/aptitude, and CS fundamentals.
Application story
I applied for the role through the on-campus placement portal at IIT Guwahati. My journey began in August with a strong focus on DSA and core computer science subjects. The process started with a rigorous online assessment (OA), which included sections on coding, math/aptitude, and CS fundamentals. After clearing the OA, I was shortlisted for the on-campus interview rounds.
Why selected/rejected for the role?
I was rejected for this role, as I couldn’t perform well in one of the rounds due to time pressure, even though the question was easy.
Preparation
Duration: 4 Months
Topics: Data Structures, Pointers, OOP, System Design, Algorithms, Dynamic Programming
Tip
Tip

Tip 1: Practice past Microsoft questions from coding platforms to get a basic understanding.

Tip 2: Study DSA topics like binary trees, graphs, and linked lists, apart from CP.

Tip 3: Have one solid project on your resume.

Application process
Where: Campus
Eligibility: No criteria, (Salary Package - 56 LPA)
Resume Tip
Resume tip

Tip 1: Have some projects on your resume.

Tip 2: Do not include false information on your resume.

Interview rounds

01
Round
Easy
Online Coding Test
Duration90 minutes
Interview date29 Oct 2025
Coding problem3

1. Encode The String

Easy
10m average time
80% success
0/40
Asked in companies
Goldman SachsMicrosoftDeloitte

You are given a string ‘S’ of length ‘N’. The string can be encoded using the following rules:

1) If the ‘i-th’ character is a vowel, change it to the next character in the alphabetical sequence. For example, the next character of ‘o’ is ‘p’.

2) If the ‘i-th’ character is a consonant, change it to the previous character in the alphabetical sequence. For example, the previous character of ‘h’ is ‘g’.

3) The next character of ‘z’ is ‘a’.

4) The previous character of ‘a’ is ‘z’.

Find the encoded string.

Example :
‘N’ = 4, ‘S’ = “code”

Character ‘c’ gets changed to ‘b’.
Character ‘o’ gets changed to ‘p’.
Character ‘d’ gets changed to ‘c’.
Character ‘e’ gets changed to ‘f’.

Encoded string = “bpcf”
Problem approach

Step 1: The Binary Analogy

Think of the characters as powers of 2.

'a' = 20=1

'b' = 21=2

'c' = 22=4

... and so on.

Merging two 'a's (1+1) gives one 'b' (2). Merging two 'b's (2+2) gives one 'c' (4). Since we want the lexicographically largest string, we want the highest possible characters at the beginning of the string. This is exactly how a binary number works: the most significant bits represent the highest powers of 2.
Step 2: Convert n to Binary

Because you start with n 'a's, your "total value" is n×20. To find the largest characters you can form, represent n in base 2.

Each bit i that is set to 1 in the binary representation of n corresponds to one character at the i-th position of the alphabet.

Example: If n=13, the binary is 11012​.

23 (8), 22 (4), and 20 (1).

These correspond to the 4th, 3rd, and 1st letters: d, c, and a.

Step 3: Construct the String

To make the string lexicographically largest, sort these characters in descending order.

Using the n=13 example: The characters are d, c, a.

The result is "dca".

Since n≤109 and 229<109<230, the maximum character you can reach is roughly the 30th letter. However, the English alphabet only has 26 letters.

Step 4: Handling the 'z' Limit

The alphabet caps at 'z' (the 26th letter). If your binary representation suggests characters beyond 'z' (bits i≥25):

Any value equivalent to 225 or higher must be converted back into 'z's.

Value of 'z' = 225.

Number of 'z's = ⌊n/225⌋.

The remainder (n(mod225)) is then converted to binary to find the characters from 'y' down to 'a'.

Try solving now

2. Make Array Elements Equal

Moderate
25m average time
75% success
0/80
Asked in companies
CIS - Cyber InfrastructureMicrosoftMakeMyTrip

You are given an array of integers of size ‘N’. You have to make the elements of the array equal, and the cost of changing the element ‘x’ to ‘y’ is abs(x -y). Your task is to find the minimum cost to make the elements of the array equal.

For example:
Consider ARR = [3, 4, 5] now suppose if we want to change every element value to 4, then the cost of changing 3 to 4 is |3 - 4| which is 1, and the cost of changing 5 to 4 is |5 - 4| which is 1, so the total cost is 1 + 1 = 2. The value 2 is the minimum cost to make all values in the array equal. Hence, the answer is 2.
Problem approach

This problem is a mathematical optimization task often categorized as a "Greedy" or "Brute Force with Observation" problem. The core challenge is deciding when to use the two-element increment (cost2) versus the single-element increment (cost1).
Problem Statement

Title: Minimum Cost to Equalize Array

You are given an array nums and two cost values: cost1 (cost to increment one element) and cost2 (cost to increment two distinct elements). Find the minimum cost to make all elements in the array equal.

Operation 1: nums[i] += 1 for cost1.

Operation 2: nums[i] += 1 and nums[j] += 1 for cost2.

Constraint: The target value must be at least the current maximum element in the array.

Solution in Steps
Step 1: Determine the Search Range for the Target

Let max_val be the maximum element in the original array. The final equalized value T must be ≥max_val. Interestingly, the optimal T isn't always max_val; increasing T further might allow more "pairs" to be used (if cost2 is cheap), potentially lowering the total cost. Usually, checking T up to 2×max_val is sufficient.
Step 2: Calculate Total Increments Needed

For a fixed target T:

Calculate the gap for each element: gapi​=T−nums[i].

Find the total sum of gaps: S=∑gapi​.

Identify the maximum gap: Gmax​=max(gapi​).

Step 3: Calculate Minimum Cost for Target T

The cost calculation depends on the relationship between cost1 and cost2:

Case A: 2×cost1≤cost2
It is always cheaper to use cost1 twice than cost2 once.
Cost =S×cost1.

Case B: cost2<2×cost1
We want to use cost2 as much as possible.

Subcase 1 (Restricted by Gmax​): If the largest gap is more than all other gaps combined (Gmax​>S−Gmax​), we can only pair other elements with the largest gap.

Pairs possible: P=S−Gmax​.

Remaining single increments: R=Gmax​−P.

Cost =(P×cost2)+(R×cost1).

Subcase 2 (Balanced Gaps): If Gmax​≤S−Gmax​, we can pair almost everything.

If S is even: Pairs =S/2. Cost =(S/2)×cost2.

If S is odd: Pairs =(S−1)/2. Cost =((S−1)/2×cost2)+cost1.

Step 4: Iterate and Compare

Loop through possible values of T (from max_val to 2×max_val), calculate the cost for each using the logic above, and keep track of the global minimum. Apply modulo 109+7 to the final result.

Try solving now

3. Reorder Edges

Moderate
30m average time
70% success
0/80
Asked in companies
AtlassianMicrosoftCoinDCX

You are given a connected directed acyclic graph of ‘N’ nodes and ‘N’ - 1 edges, such that there is only one edge between any two nodes. You can perform the below operation on the given graph zero or more times:

1) Choose two nodes, ‘X’ and ‘Y’, such that there exists an edge between ‘X’ and ‘Y’.

2) Change the direction of this edge, i.e., if this edge is directed from ‘X’ to ‘Y’, change the direction of this edge to be directed from ‘Y’ to ‘X’ and vice versa.

Your task is to reorder the edges of the given graph in such a way that there exists a directed path from each node to node 0, using the minimum number of operations.

Problem approach

Step 1: Build an Adjacency List with Directional Metadata

Since the input connections give us directed edges, we need a way to traverse the tree in any direction while still knowing which way the original road pointed.

Represent the graph as an adjacency list where each entry stores the neighbor and a boolean (or integer) indicating if the edge is original (pointing away from 0) or artificial (pointing toward 0).

Example: For [a, b], add (b, true) to adj[a] and (a, false) to adj[b].

Step 2: Perform a Traversal (DFS or BFS) starting from City 0

Start a traversal from the capital (City 0). Because we are moving away from the root to visit all nodes:

If we encounter an original edge (a -> b), it means the road is currently pointing away from the capital. We must reverse it to allow city b to reach a (and eventually 0).

If we encounter an artificial edge (b -> a), it means the road is already pointing toward the capital. No change is needed.

Step 3: Accumulate the Count

Every time you traverse an "original" edge during your DFS/BFS, increment a counter. Since it's a tree, you will visit every edge exactly once. The final count is the minimum number of reorientations required.

Try solving now
02
Round
Medium
Video Call
Duration60 minutes
Interview date29 Nov 2025
Coding problem1

1. Trapping Rain Water

Moderate
15m average time
80% success
0/80
Asked in companies
HCL TechnologiesGrofersQualcomm

You have been given a long type array/list 'arr’ of size 'n’.


It represents an elevation map wherein 'arr[i]’ denotes the elevation of the 'ith' bar.



Note :
The width of each bar is the same and is equal to 1.
Example:
Input: ‘n’ = 6, ‘arr’ = [3, 0, 0, 2, 0, 4].

Output: 10

Explanation: Refer to the image for better comprehension:

Alt Text

Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Problem approach

Step 1: Initialize Boundary Pointers

Place two pointers, left at the beginning (0) and right at the end (n−1) of the array. Also, maintain two variables, left_max and right_max, initialized to 0, to track the highest bars encountered from both directions.
Step 2: Iterate and Compare Heights

While left < right:

Compare height[left] and height[right].

If height[left] < height[right]: The water level is bottlenecked by the left side.

If height[left] >= left_max, update left_max.

Else, add left_max - height[left] to your total trapped water.

Move the left pointer forward.

Else (height[right] <= height[left]): The water level is bottlenecked by the right side.

If height[right] >= right_max, update right_max.

Else, add right_max - height[right] to your total trapped water.

Move the right pointer backwards.

Step 3: Return Total

Once the pointers meet, the accumulated sum represents the total volume of trapped water. This approach ensures O(N) time complexity and O(1) space complexity.

Try solving now

Here's your problem of the day

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

Skill covered: Programming

What does the SQL function NOW() return?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
5 rounds | 15 problems
Interviewed by Microsoft
4199 views
0 comments
0 upvotes
company logo
SDE - 1
5 rounds | 7 problems
Interviewed by Microsoft
2780 views
0 comments
0 upvotes
company logo
SDE - 1
1 rounds | 2 problems
Interviewed by Microsoft
7492 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 7 problems
Interviewed by Microsoft
1330 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
115740 views
24 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
35391 views
7 comments
0 upvotes
company logo
SDE - 1
3 rounds | 11 problems
Interviewed by Amazon
21942 views
4 comments
0 upvotes