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 | 9 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
Hard
Online Coding Test
Duration90 Minutes
Interview date14 Jul 2021
Coding problem3

This round had 3 coding questions and the difficulty of the questions ranged from Moderate to Hard level.

1. Jump Game

Moderate
25m average time
75% success
0/80
Asked in companies
ShareChatUberOracle

There is an array 'JUMP' of size 'N' which is 1-indexed and you are currently at index 1. Your goal is to reach index 'N' (end).


When you are at index 'i', you can jump a maximum length of 'JUMP[i]' which means you can make a jump of size 1 to JUMP[i]. Return true if you can reach the end otherwise false.


Example:-
N = 5
JUMP = [1,2,3,4,5]

ANSWER:- The answer should be YES as you can jump from 1st index to 2nd index, from 2nd index to 4th index, and from 4th index to 5th index.
Problem approach

Approach : 

1) Take the variables 'MINJUMP' to store the minimum number of jumps,’curEnd’ to store the farthest index we can go from the current index and 'CURFARTHEST' to store the farthest we can go with the help of elements we have encountered till now.

2) We initialise the value of 'CUREND' and 'CURFARTHEST' to be 0.

3) Let's say the range of the current jump is ['CURBEGIN', 'CUREND'].

4) 'CURFARTHEST' is the farthest point that all points in ['CURBEGIN', 'CUREND'] can reach.

5) Once the current index ‘i’ reaches the 'CUREND' we have reached the maximum possible index we could have reached in 1 jump, therefore, we trigger another jump.

6) We then set the new 'CUREND' with 'CURFARTHEST', until 'CURFARTHEST' is equal to the last index of the given sequence.


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

Try solving now

2. Sibling Nodes

Moderate
20m average time
80% success
0/80
Asked in companies
AmazonMicrosoftDirecti

You have been given a Binary Tree of ‘N’ nodes, where the nodes have integer values. Your task is to print all nodes that don’t have a sibling node.

Note:
1. Node ‘U’ is said to be a sibling of node ‘V’ if and only if both ‘U’ and ‘V’ have the same parent.
2. Root 1 is a sibling node.
Problem approach

Approach (Using BFS) : 

1) Declare an empty array say, ‘answer’ to store all nodes that don’t have a sibling node.

2) Declare an empty queue and push the root node of the binary tree to it.

3) Run a loop until the queue is not empty.

4) Pop the front element from the queue, say ‘current’.

5) If both, left and the right child of ‘node’ are not NULL, then push ‘node -> left’ and ‘node -> right’ in the queue.

6) Else two conditions will occur:

7) If the right child of ‘node’ is not NULL, then add data of the right child to ‘answer’ and push ‘node -> right’ in the queue.

8) If the left child of ‘node’ is not NULL, then add data of the left child to ‘answer’ and push ‘node -> left’ in the queue.

9) Sort the ‘answer’.

10) Finally, return the ‘answer’.


TC : O(N), where N = total number of nodes in the given binary tree.
SC : O(N)

Try solving now

3. Minimum steps to reach target by a Knight

Moderate
25m average time
60% success
0/80
Asked in companies
MicrosoftIntuitGroww

You have been given a square chessboard of size ‘N x N’. The position coordinates of the Knight and the position coordinates of the target are also given.

Your task is to find out the minimum steps a Knight will take to reach the target position.

alt text

Example:
knightPosition: {3,4}
targetPosition: {2,1}

alt text

The knight can move from position (3,4) to positions (1,3), (2,2) and (4,2). Position (4,2) is selected and the ‘stepCount’ becomes 1. From position (4,2), the knight can directly jump to the position (2,1) which is the target point and ‘stepCount’ becomes 2 which is the final answer. 

Note:

1. The coordinates are 1 indexed. So, the bottom left square is (1,1) and the top right square is (N, N).

2. The knight can make 8 possible moves as given in figure 1.

3. A Knight moves 2 squares in one direction and 1 square in the perpendicular direction (or vice-versa).
Problem approach

Approach (Using BFS) : 

1) Define a class with the following data members
a. ‘X_COORDINATE’ denoting the x-coordinate
b. ‘Y_COORDINNATE’ denoting the y-coordinate
c. ‘STEP_COUNT’ denoting the number of steps.

2) Take two arrays ‘DIRECTION_X’ and ‘DIRECTION_Y’ storing the direction in which the knight can move.

3) Create a queue to store the class objects.

4) Take a visited array to mark the cells already visited and initialize it to false.

5) Push the initial position of the knight to the queue and mark it as visited.

6) Loop till the queue is not empty.

7) Pop the front element.
a. If the current cell is equal to the target cell, return the 'STEP_COUNT’ which is the minimum step a Knight will take to reach the target position.
b. Else, loop for all the reachable coordinates. If the coordinate is not yet visited and is reachable, push it to the queue along with the incremented value of ‘STEP_COUNT’.


TC : O(N^2), where N = number of rows/columns.
SC : O(N^2)

Try solving now
02
Round
Medium
Video Call
Duration60 Minutes
Interview date14 Jul 2021
Coding problem4

This round went for about 50-60 minutes where I had to code two questions related to DSA after discussing their approaches and time and space complexities and then I was asked some questions revolving around OOPS. The interviewer was quite freindly and helped me at some places where I was facing some difficulties.

1. Evaluate Reverse Polish Notation

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

You are given an arithmetic expression in Reverse Polish Notation in the form of an array ‘EXP’. Your task is to evaluate the value of the given expression. Since the final value can be large, output it Modulo 10^9+7.

Reverse Polish Notation is a mathematical notation in which the operator appears in the expression after the operands.

For Example:

You are given ‘EXP’ = {‘2’,’3’,’1’,’*’,’+’,’9’,’-’}. Then the result will be -4.
2 3 1 * + 9 -

- : ( ) - ( )
9 : ( ) - (9)
+ : ( ( ) + ( ) ) - (9)
'*':  ( ( ) + ( ( ) * ( ) ) ) - (9)
1 : ( ( ) + ( ( ) * (1) ) ) - (9)
3 : ( ( ) + ( (3) * (1) ) ) - (9)
2 : ( (2) + ( (3) * (1) ) ) - (9) 

Result = (2 + 3) - 9 = 5 - 9 = -4 
Problem approach

The problem statement was quite straight forward but I was asked to code the Space Optimised Approach. I had
previously solved this question using a stack but without using any extra space required a liitle bit of observation that
the input vector given can also be used as a stack .

Approach 1 (Using Stack ) :
1) If the current token is a operand (number), push it into the stack
2) If the token is a operator, pop the top two operands from the stack. Find the result of the operation using the
operator and two operands and push the result back into stack
3) Finally, the stack will contain the result of evaluated reverse polish expression.


TC : O(N)
SC: O(N)


Approach 2 (Without using stack ) :
If we are allowed to modify the input vector, we can optimize the space usage by using the input vector itself as a
stack rather than an explicit stack.

1) Here, we will maintain a pointer top which will point to the top index of tokens (our implicit stack).
2) Everytime we receive a integer token, we will push it at the index pointed by top.
3) Similarly, when we receive an operator, we can pop the top two operands and after computing the result on them,
push it back into tokens.

The only important thing here is properly maintaining the top pointer, so that we correctly access the elements the
operands.


TC : O(N)
SC: O(1)

Try solving now

2. LCA In A BST

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

You are given a binary search tree of integers with N nodes. You are also given references to two nodes 'P' and 'Q' from this BST.


Your task is to find the lowest common ancestor(LCA) of these two given nodes.


The lowest common ancestor for two nodes P and Q is defined as the lowest node that has both P and Q as descendants (where we allow a node to be a descendant of itself)


A binary search tree (BST) is a binary tree data structure which has the following properties.

• The left subtree of a node contains only nodes with data less than the node’s data.
• The right subtree of a node contains only nodes with data greater than the node’s data.
• Both the left and right subtrees must also be binary search trees.


For example:
'P' = 1, 'Q' = 3
tree = 2 1 4 -1 -1 3 -1 -1 -1,

The BST corresponding will be- 

Here, we can clearly see that LCA of node 1 and node 3 is 2.
Problem approach

Approach : 

1) Create a recursive function that takes a node and the two values n1 and n2.
2) If the value of the current node is less than both n1 and n2, then LCA lies in the right subtree. Call the recursive
function for the right subtree.
3) If the value of the current node is greater than both n1 and n2, then LCA lies in the left subtree. Call the recursive
function for the left subtree.
4) If both the above cases are false then return the current node as LCA.

TC : O(h), where h=Height of the BST
SC : O(h)

Try solving now

3. OOPS Question

What is Diamond Problem in C++ and how do we fix it?

Problem approach

The Diamond Problem : The Diamond Problem occurs when a child class inherits from two parent classes who both
share a common grandparent class i.e., when two superclasses of a class have a common base class.

Solving the Diamond Problem in C++ : The solution to the diamond problem is to use the virtual keyword. We make
the two parent classes (who inherit from the same grandparent class) into virtual classes in order to avoid two copies
of the grandparent class in the child class.

4. OOPS Question

What is meant by Garbage Collection in OOPs world?

Problem approach

Object-oriented programming revolves around entities like objects. Each object consumes memory and there can be multiple objects of a class. So if these objects and their memories are not handled properly, then it might lead to certain memory-related errors and the system might fail.

Garbage collection refers to this mechanism of handling the memory in the program. Through garbage collection, the unwanted memory is freed up by removing the objects that are no longer needed.

03
Round
Medium
Video Call
Duration60 Minutes
Interview date14 Jul 2021
Coding problem2

This round consisted of two coding problems which involved proper coding it and explaining each and every aspect and showing the dry run over a few test cases was also necessary.

1. Implement a phone directory

Hard
50m average time
50% success
0/120
Asked in companies
AmazonMicrosoftDelhivery

You are given a list/array of strings which denotes the contacts that exist in your phone directory. The search query on a string ‘str’ which is a query string displays all the contacts which are present in the given directory with the prefix as ‘str’. One special property of the search function is that when a user searches for a contact from the contact list then suggestions (contacts with prefix as the string entered so for) are shown after the user enters each character.

Note :
If no suggestions are found, return an empty 2D array.
For Example :

alt text

In the above example everytime we enter a character, a few suggestions display the strings which contain the entered string as prefixes.
Problem approach

Approach : 

Phone Directory can be efficiently implemented using Trie Data Structure.

1) We insert all the contacts into Trie.

2) Generally search query on a Trie is to determine whether the string is present or not in the trie, but in this case we
are asked to find all the strings with each prefix of ‘str’. This is equivalent to doing a DFS traversal on a graph.

3) From a Trie node, visit adjacent Trie nodes and do this recursively until there are no more adjacent. This recursive
function will take 2 arguments one as Trie Node which points to the current Trie Node being visited and other as the
string which stores the string found so far with prefix as ‘str’.

4) Each Trie Node stores a boolean variable ‘isLast’ which is true if the node represents end of a contact(word).

5) User will enter the string character by character and we need to display suggestions with the prefix formed after
every entered character.

6) Find the prefix starting with the string formed is to check if the prefix exists in the Trie, if yes then call the
displayContacts() function. In this approach after every entered character we check if the string exists in the Trie.

7) Instead of checking again and again, we can maintain a pointer prevNode‘ that points to the TrieNode which
corresponds to the last entered character by the user, now we need to check the child node for the ‘prevNode’ when
user enters another character to check if it exists in the Trie.

8) If the new prefix is not in the Trie, then all the string which are formed by entering characters after ‘prefix’ can’t be
found in Trie too.

9) So we break the loop that is being used to generate prefixes one by one and print “No Result Found” for all
remaining characters.

Try solving now

2. Bottom View Of Binary Tree

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

You are given a 'Binary Tree'.


Return the bottom view of the binary tree.


Note :
1. A node will be in the bottom-view if it is the bottom-most node at its horizontal distance from the root. 

2. The horizontal distance of the root from itself is 0. The horizontal distance of the right child of the root node is 1 and the horizontal distance of the left child of the root node is -1. 

3. The horizontal distance of node 'n' from root = horizontal distance of its parent from root + 1, if node 'n' is the right child of its parent.

4. The horizontal distance of node 'n' from root = horizontal distance of its parent from the root - 1, if node 'n' is the left child of its parent.

5. If more than one node is at the same horizontal distance and is the bottom-most node for that horizontal distance, including the one which is more towards the right.


Example:
Input: Consider the given Binary Tree:

alt text

Output: 4 2 6 3 7

Explanation:
Below is the bottom view of the binary tree.

alt text

1 is the root node, so its horizontal distance = 0.
Since 2 lies to the left of 0, its horizontal distance = 0-1= -1
3 lies to the right of 0, its horizontal distance = 0+1 = 1
Similarly, horizontal distance of 4 = Horizontal distance of 2 - 1= -1-1=-2
Horizontal distance of 5 = Horizontal distance of 2 + 1=  -1+1 = 0
Horizontal distance of 6 = 1-1 =0
Horizontal distance of 7 = 1+1 = 2

The bottom-most node at a horizontal distance of -2 is 4.
The bottom-most node at a horizontal distance of -1 is 2.
The bottom-most node at a horizontal distance of 0 is 5 and 6. However, 6 is more towards the right, so 6 is included.
The bottom-most node at a horizontal distance of 1 is 3.
The bottom-most node at a horizontal distance of 2 is 7.

Hence, the bottom view would be 4 2 6 3 7


Problem approach

Approach : 

1) Take an ordered map and a queue. The ordered map will help to store the nodes in the left to right order.

2) Push the root and the horizontal distance(which is 0 for the root) using the pair data structure, in the queue.

3) While the queue is not empty, perform the below steps :
a. Store the front element of the queue, which will be a node and the horizontal distance of that node in a variable ‘TEMP’.
b. Pop the front element.
c. Put the dequeued tree node in the map having the corresponding horizontal distance as the key. If the key is already present in the map, update its value with the current dequeued tree node.
d. If the dequeued node has a left child, push it to the queue along with the horizontal distance of the dequeued node - 1.
e. If the dequeued node has a right child, push it to the queue along with the horizontal distance of the dequeued node + 1.

4) Traverse the map and keep storing the values of each key in a vector.

5) Finally, return the vector which will be our required nodes in the bottom view of the binary tree.


TC : O(N*log(N)), where N = number of nodes in the binary tree.
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