D.E.Shaw interview experience Real time questions & tips from candidates to crack your interview

SDE - 1

D.E.Shaw
upvote
share-icon
3 rounds | 10 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 5 Months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Campus
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Online Coding Test
Duration90 Minutes
Interview date19 Aug 2021
Coding problem3

This round had 3 coding questions. The first two were of moderate level and the third one was a bit hard and was related to Dynamic Programming.

1. Make Maximum Number

Moderate
18m average time
85% success
0/80
Asked in companies
SamsungWalmartD.E.Shaw

Given a linked list such that each node represents a digit. Construct the maximum number possible from the given digits.

You just need to print the maximum Integer that can be formed

Problem approach

Approach : 

1) Traverse the linked list from start to end and make frequency array of all digits (0-9) present in the linked list.

2) Make the string starting from the maximum of digits (0-9) present in the linked list i.e first append all the 9’s in the answer string then append all the 8’s at the end of the answer string so on for all the other digits in the decreasing order. 

3) Finally, return the formed answer string.


TC : O(N), where N = length of the Linked List
SC : O(1)

Try solving now

2. Chocolate Problem

Moderate
15m average time
85% success
0/80
Asked in companies
EcomExpressIBMMicrosoft

Given an array/list of integer numbers 'CHOCOLATES' of size 'N', where each value of the array/list represents the number of chocolates in the packet. There are ‘M’ number of students and the task is to distribute the chocolate to their students. Distribute chocolate in such a way that:

1. Each student gets at least one packet of chocolate.

2. The difference between the maximum number of chocolate in a packet and the minimum number of chocolate in a packet given to the students is minimum.

Example :

Given 'N' : 5 (number of packets) and 'M' : 3 (number of students)

subsequence

And chocolates in each packet is : {8, 11, 7, 15, 2}

All possible way to distribute 5 packets of chocolates among 3 students are -

( 8,15, 7 ) difference of maximum-minimum is ‘15 - 7’ = ‘8’
( 8, 15, 2 ) difference of maximum-minimum is ‘15 - 2’ = ‘13’ 
( 8, 15, 11 ) difference of maximum-minimum is ‘15 - 8’ = ‘7’
( 8, 7, 2 ) difference of maximum-minimum is ‘8 - 2’ = ‘6’
( 8, 7, 11 ) difference of maximum-minimum is ‘11 - 7’ = ‘4’
( 8, 2, 11 ) difference of maximum-minimum is ‘11 - 2’ = ‘9’
( 15, 7, 2 ) difference of maximum-minimum is ‘15 - 2’ = 13’
( 15, 7, 11 ) difference of maximum-minimum is ‘15 - 7’ = ‘8’
( 15, 2, 11 ) difference of maximum-minimum is ‘15 - 2’ = ‘13’
( 7, 2, 11 ) difference of maximum-minimum is ‘11 - 2’ = ‘9’

Hence there are 10 possible ways to distribute ‘5’ packets of chocolate among the ‘3’ students and difference of combination (8, 7, 11) is ‘maximum - minimum’ = ‘11 - 7’ = ‘4’ is minimum in all of the above.
Problem approach

Approach : 

1) Suppose the given array is ‘CHOCOLATES’.

2) Sort the given array.

3) Find the subarray with the minimum difference of the last and first elements.

4) To store minimum difference we use a variable (say, ‘minVal’) and the initial value is ‘INFINITE’

5) Run a loop from 0 to ‘N’ - ‘M’ - 1(say, iterator ‘i’)

6) If 'CHOCOLATES'[i] - ‘CHOCOLATES’[i - M + 1] is less than ‘minVal’ then update ‘minVal’ with ‘CHOCOLATES’[i] - ‘CHOCOLATES’[i - M + 1] because we can get minimum difference possible with ‘i’th and (’i' - ‘M’ + 1)’th packet.

7) Finally, return ‘minVal’.


TC : O(N * log(N)), where N = the number of packets of chocolates.
SC : O(1)

Try solving now

3. LCS of 3 strings

Hard
45m average time
50% success
0/120
Asked in companies
UberD.E.Shaw

Given three strings A, B and C, the task is to find the length of the longest common sub-sequence in all the three strings A, B and C.

A subsequence of a string is a new string generated from the original string with some characters(can be 0) deleted without changing the relative order of the remaining characters. (For eg, "cde" is a subsequence of "code" while "cdo" is not). A common subsequence of two or more strings is a subsequence that is common to all the strings.

Note
You don’t have to print anything, it has already been taken care of. Just complete the function. 
If there is no common subsequence, return 0.
Problem approach

Approach : 

1) The idea is to create a 3-D DP of size n*m*k.

2) Initially, all the elements of the DP table will be 0.

3) Now, the value DP[i][j] means denotes the length of the longest common sub-sequence of string A[0..i], B[0..j], and C[0..k].

4) The detailed algorithm to fill the DP table will be as follows:

Loop 1: For i = 1 to N:
Loop 2: For j = 1 to M:
Loop 3: For k = 1 to K:

if(A[i] == B[j] == C[k] ), DP[i][j][k] += DP[i-1][j-1][k-1]
else DP[i][j][k] = max(DP[i-1][j][k], DP[i][j-1][k], DP[i][j][k-1]) 

5) Return DP[n][m][k].


TC : O(n*m*k), where n, m, k are the length of the strings A, B, C respectively.
SC : O(n*m*k)

Try solving now
02
Round
Medium
Video Call
Duration60 Minutes
Interview date19 Aug 2021
Coding problem4

This round had 2 questions of DS/Algo to solve under 60 minutes and 2 questions related to Operating Systems.

1. Buy and Sell Stock

Hard
0/120
Asked in companies
Samsung R&D InstituteMicrosoftSalesforce

You are Harshad Mehta’s friend. He told you the price of a particular stock for the next ‘n’ days.


You are given an array ‘prices’ which such that ‘prices[i]’ denotes the price of the stock on the ith day.


You don't want to do more than 2 transactions. Find the maximum profit that you can earn from these transactions.


Note

1. Buying a stock and then selling it is called one transaction.

2. You are not allowed to do multiple transactions at the same time. This means you have to sell the stock before buying it again. 
Example:
Input: ‘n’ = 7, ‘prices’ = [3, 3, 5, 0, 3, 1, 4].

Output: 6

Explanation: 
The maximum profit can be earned by:
Transaction 1: Buying the stock on day 4 (price 0) and then selling it on day 5 (price 3). 
Transaction 2: Buying the stock on day 6 (price 1) and then selling it on day 6 (price 4).
Total profit earned will be (3 - 0) + ( 4 - 1) = 6. 
Problem approach

Approach : 

1) Initialize variables 'FIRSTBUY' as the minimum negative value, ‘FIRSTSELL’ as 0, ‘SECONDBUY’ as the minimum negative value, and ‘SECONDSELL’ as 0.
‘FIRSTSELL’ will be the profit after the first transaction and ‘SECONDSELL’ will be the profit after the second transaction.

2) For ‘i’ in range days:
2.1) Maximise 'FIRSTBUY' as max( 'FIRSTBUY' , - ‘PRICES[i]’), this is the amount left after your first buy.
2.2) Maximise ‘FIRSTSELL’ as max( ‘FIRSTSELL’ , 'FIRSTBUY' + ‘PRICES[i]’).
2.3) Maximise ‘SECONDBUY’ as max( ‘SECONDBUY’ , ‘FIRSTSELL’ - ‘PRICES[i]’).
2.4) Maximise ‘SECONDSELL’ as max( ‘SECONDSELL’ , ‘SECONDBUY’ + ‘PRICES[i]’).

3) Return ‘SECONDSELL’ as it is the final profit or the final amount left with you.

TC : O(N), where N = number of days
SC : O(1)

Try solving now

2. Count smaller people on right side

Easy
10m average time
90% success
0/40
Asked in company
D.E.Shaw

You are given the height of N people standing in a queue in an array 'HEIGHT'. For each person, you need to calculate the number of people on the right side of the given person who is smaller in height.

For example:

For N = 4 and height[] = [6, 3, 7, 2]

For the first person with a height of 6, the people on the right side with a height smaller than 6 are the 2nd and 4th person. So for the first person, the count is 2.

For the second person with height 3, the person on the right side with a height smaller than 3 is the 4th person. So for the second person, the count is 1.

For the third person with a height of 7, the person on the right side with a height smaller than 7 is the 4th person. So for the third person, the count is 1.

For the last person, the count is 0 as there are no people left on the right-hand side. So for the last person, the count is 0.

So the Count[] is [2, 1, 0, 0].
Problem approach

Approach : This question was similar to the famous problem "Count Inversions" and so I thought of applying Merge Sort here. 

1) By modifying the merging array part of merge sort, we can calculate the required ans.

2) During merging of two halves, when the higher index element is less than the lower index element, it represents that the higher index element is smaller than all the elements after that lower index because the left part is already sorted. Hence add up to all the elements after the lower index element for the required count.

3) We will use the function MergeCount() to count the ans for a particular range of people. Initially, our range is 0 to n-1.

4) The MergeCount() function will perform three operation.
4.1) Recursively call MergeCount() for the left half.
4.2) Recursively call MergeCount() for the right half.
4.3) Call another helper function Merge() to merge both the halves.


TC : O(N * logN), where N = number of people.
SC : O(N)

Try solving now

3. OS Question

Define Process and Threads in OS

Problem approach

Process : A process is an instance of a program that is being executed. When we run a program, it does not execute
directly. It takes some time to follow all the steps required to execute the program, and following these execution
steps is known as a process.

A process can create other processes to perform multiple tasks at a time; the created processes are known as clone
or child process, and the main process is known as the parent process. Each process contains its own memory
space and does not share it with the other processes. It is known as the active entity.



Thread : A thread is the subset of a process and is also known as the lightweight process. A process can have more
than one thread, and these threads are managed independently by the scheduler. All the threads within one process
are interrelated to each other. Threads have some common information, such as data segment, code segment, files,
etc., that is shared to their peer threads. But contains its own registers, stack, and counter.

4. OS Question

What are the different types of semaphores ?

Problem approach

There are two main types of semaphores i.e. counting semaphores and binary semaphores.

1) Counting Semaphores :
These are integer value semaphores and have an unrestricted value domain. These semaphores are used to
coordinate the resource access, where the semaphore count is the number of available resources. If the resources
are added, semaphore count automatically incremented and if the resources are removed, the count is decremented.

2) Binary Semaphores :
The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. The wait operation only
works when the semaphore is 1 and the signal operation succeeds when semaphore is 0. It is sometimes easier to
implement binary semaphores than counting semaphores.

03
Round
Medium
Video Call
Duration60 Minutes
Interview date19 Aug 2021
Coding problem3

This round had 3 coding questions in which I first had to explain my approach with proper complexity analysis and then code up the solution. I found the first problem to be a bit on the harder side compared to the rest of the 2 problems.

1. Longest Increasing Path In A 2D Matrix

Hard
10m average time
90% success
0/120
Asked in companies
PhonePeSamsungFacebook

You have been given a MATRIX of non-negative integers of size N x M where 'N' and 'M' denote the number of rows and columns, respectively.

Your task is to find the length of the longest increasing path when you can move to either four directions: left, right, up or down from each cell. Moving diagonally or outside the boundary is not allowed.

Note: A sequence of integers is said to form an increasing path in the matrix if the integers when traversed along the allowed directions can be arranged in strictly increasing order. The length of an increasing path is the number of integers in that path.

For example :

3 2 2
5 6 6
9 5 11 

In the given matrix, 3 →  5 →  6 and 3 →  5 →  9 form increasing paths of length 3 each.
Problem approach

Approach : 

1) We maintain a 2D array dp of size N*M. Since the increasing path can start from any point in the matrix, we use dp[i][j] to store the length of the longest increasing path starting from location (i, j). This ensures that we do not recalculate a visited location. 

2) Now, we perform a DFS from each cell with the current cell as (x, y). We compare the cells in the four directions (dx, dy) and skip cells that are out of boundary or for which mat[x][y] > mat[dx][dy].

If the cell (dx, dy) satisfies the conditions, we perform dfs from that cell and update maxLen as max of maxLen and 1 + (dfs from dx, dy).

3) We then update dp[x][y] with maxLen.

4) Finally, we return the maximum length of the increasing path as result.


TC : O(N*M), where N and M denote the number of rows and columns respectively
SC : O(N*M)

Try solving now

2. Gas Stations

Moderate
10m average time
90% success
0/80
Asked in companies
OlaPhonePeApple

You have been given a circular path. There are 'N' petrol pumps on this path that are numbered from 0 to N - 1 (Both inclusive). Each petrol pump has two values associated with it:

1)The amount of petrol that is available at this particular petrol pump.
2)The distance to reach the next petrol pump.

You are on a truck having an empty tank of infinite capacity. You can start the tour from any of the petrol pumps. Your task is to calculate the first petrol pump from where the truck will be able to complete the full circle or determine if it is impossible to do so.

You may assume that the truck will stop at every petrol pump and it will add the petrol from that pump to its tank. The truck will move one kilometre for each litre of petrol consumed.

Problem approach

Approach : 

1) We can choose every index to be our starting point and check whether we can complete the round trip starting from that index.

2) For each start point, we will run a loop starting from this index. If at any point, petrol available in the truck is not sufficient to move on to the next petrol pump, we know this is a bad starting point. So, we break the loop and try the same for the next start point.

3) As soon as we find a start point which results in a complete tour of all pumps, we return its index.

4) If no such index exists we will simply return -1.


TC : O(N^2), where N = total number of petrol stations
SC : O(1)

Try solving now

3. Rabbit Jumping

Easy
20m average time
80% success
0/40
Asked in companies
Expedia GroupXebiaNagarro Software

You are given ‘n’ carrots numbered from 1 to ‘n’. There are k rabbits. Rabbits can jump to carrots only with the multiples of Aj(Aj,2Aj,3Aj…) for all rabbits from 1 to k.

Whenever Rabbit reaches a carrot it eats a little carrot. All rabbits start from the same beginning point. You have to determine the remaining carrots(i.e., carrots which are not eaten by any rabbit) after all rabbits reach the end.

Problem approach

Approach : 

1) Create a boolean array of size n + 1 with default value false.

2) Run a loop from i=0 to k. If A[i] is marked true then we don’t need to traverse its multiples as they have been already traversed. Else Traverse all multiples of A[i] less than n. The carrots which are visited mark it true.

3) After doing traversal count the values from 1 to n with false values. Return this value.


TC : O(N * log(max(A[i]))) where N = number of carrots. 
SC : O(N)

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

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

Choose another skill to practice
Similar interview experiences
SDE - 1
4 rounds | 7 problems
Interviewed by D.E.Shaw
12831 views
1 comments
0 upvotes
SDE - 1
2 rounds | 4 problems
Interviewed by D.E.Shaw
3170 views
0 comments
0 upvotes
SDE - 1
3 rounds | 10 problems
Interviewed by D.E.Shaw
1258 views
0 comments
0 upvotes
SDE - 1
3 rounds | 3 problems
Interviewed by D.E.Shaw
0 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