Join Regular Classroom : Visit ClassroomTech

D.E Shaw Interview Questions + Coding Solutions – codewindow.in

Hot Topics

D.E Shaw Solutions

Technical Round

Given 9 balls all of which weigh the same except for one, what is the minimum of weighings necessary to find the ball weighs more (or less).

The minimum number of weighings required to find the ball that weighs differently from the others is 3.
Here’s one way to find the heavy/light ball with 3 weighings:
  1. Divide the balls into three groups of three and weigh two of the groups against each other.
  2. If the two groups weigh the same, the heavy/light ball is in the third group. If one group weighs more/less, then it contains the heavy/light ball.
  3. Weigh any two balls from the group determined in step 2. If they weigh the same, the heavy/light ball is the third one. If one of them weighs more/less, then it is the heavy/light ball.
This approach guarantees that you will find the heavy/light ball in three weighings or less.

For a 3 sets tennis game, would you bet on it finishing in 2 sets or 3 sets?

As an AI language model, I do not have personal opinions or biases. However, in a 3 sets tennis game, the outcome can either be 2 sets or 3 sets. The probability of the game finishing in 2 sets or 3 sets will depend on various factors such as the players’ current form and performance, their past head-to-head records, their playing styles, etc. These factors make it difficult to predict the outcome of a tennis game with certainty.

You are given two Gaussian variables: X_1 and X_2 with means m_1, m_2 and variance v_1, v_2. Suppose you know the sum X_1 + X_2 is equal to n. What is the expected value of X_2?

The expected value of a sum of two random variables is equal to the sum of their expected values. Therefore, the expected value of X_1 + X_2 is equal to the expected value of X_1 + the expected value of X_2, which is equal to m_1 + m_2 = n.
So, the expected value of X_2 is equal to n – m_1.
Note: This result assumes that X_1 and X_2 are independent random variables. If they are not independent, their covariance will also have to be taken into account when computing the expected value of X_2.

You call to someone’s house and asked if they have two children. The answer happens to be yes. Then you ask if one of their children is a boy. The answer happens to be yes again. What’s the probability that the second child is a boy?

Given the information that the household has two children and one of them is a boy, it is not possible to determine the probability that the second child is a boy with certainty.
If the first child is a boy, the probability that the second child is a boy would be 50%. However, if the first child is a girl, the probability that the second child is a boy would still be 50%.
Without additional information, it is not possible to determine the probability that the second child is a boy.

You are in a room with 100 lights, initially all off. If you first toggle every light, then every second, and so forth up to 100, which lights will be on at the end?

At the end of the toggling process, the lights that will be on are the ones that have an odd number of switches.
The first toggle will turn on all 100 lights. Then, in the second round of toggling, every second light will be turned off, leaving only the lights at odd positions on. In the third round of toggling, every fourth light will be turned on, leaving the lights at positions 1, 5, 9, and so on, on. This pattern continues for 100 rounds, with each round of toggling affecting only the lights at positions that are multiples of the current round’s number.
Therefore, at the end, the lights that will be on are the ones at positions 1, 3, 5, 7, 9, 11, …, 99. These are the lights that have an odd number of switches.

Ten people are bidding on a stock at 90, while 100 people are offering to sell it at 91. What price is the next trade?

In this scenario, the next trade will occur at a price of 91.
The price at which a trade takes place is determined by supply and demand, which is represented by the number of buyers bidding for the stock and the number of sellers offering it. In this case, there are 10 buyers bidding for the stock at 90 and 100 sellers offering it at 91.
Since there are more sellers than buyers, the market price will adjust to the lowest price at which all the sellers are willing to sell, which is 91. This means that the next trade will occur at a price of 91, and the buyer will have to pay 91 for the stock.

Three of my 150 friends have phone numbers ending in a permutation of the digits 0, 1, 4, and 9. Is this surprising?

No, it is not surprising that three of your 150 friends have phone numbers ending in a permutation of the digits 0, 1, 4, and 9.
Given that there are 10 digits to choose from for the last four digits of a phone number, there are 10,000 possible combinations of four digits (10 x 10 x 10 x 10). So, given a sample size of 150 friends, it is not unexpected to find three of them with phone numbers ending in a permutation of 0, 1, 4, and 9.
In fact, based on the expected frequency of each combination of four digits, we can calculate that the expected number of friends with phone numbers ending in a permutation of 0, 1, 4, and 9 would be approximately 1.5 friends (150 x 0.0001). So, having three friends with phone numbers ending in these digits is within the expected range.

Write C code that, given number n from the interval [0,32], produce integer number with n least-significant bit sets to 1, and other bits set to 0 (practically, write a decoder).

Here is the code in C that will produce an integer number with n least-significant bits set to 1:
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int result = (1 << n) - 1;
    printf("%d\n", result);
    return 0;
}
In this code, n is the input number from the interval [0, 32]. The 1 << n expression will shift the value of 1 to the left by n bits, and the - 1 will set the n least-significant bits to 1, while other bits will be set to 0. The result is then printed to the standard output.

There are 100 prisoners on an island. Starring from Day 1, a guard will play the following game with them. On the n th day, a random prisoner will be brought into a room, which contains a switch that is either on or off. After he left the room, the guard will then ask the prisoner if everybody has been to the room. He can answer either “Yes” or “I dun know”. If he answered “yes” and he is correct, everyone is free’ otherwise everyone dies. If he answered “I dun know”, the game continues: a prisoner will be chosen at random on (n+1)-th day and so on. Now these 100 prisoners are free to meet and discuss a strategy on the night of 0th day. Afterwards they will not be able to see anyone else at all. No other communication is possible except the binary switch in the room. Is there a sure-fire strategy to free all of them?

No, there is no sure-fire strategy to free all the prisoners. The problem is known as the 100 Prisoners Problem and it is a classic example of a paradoxical situation in game theory. The only way for all the prisoners to be freed is for one of the prisoners to correctly guess the state of the switch, but this is only possible if each prisoner visits the room and sees the switch’s state, which is not allowed by the rules of the game. Hence, it is impossible for all the prisoners to be freed.

You have many soccer teams, which will compete against each other in 5 rounds of elimination competitions until one team remains. You have 1000 dollars, how should you bet on each round of competition to ensure maximum profit?

The optimal betting strategy to ensure maximum profit in this scenario would be to use the Kelly Criterion. The Kelly Criterion is a formula used to determine the optimal fraction of your bankroll to bet on a favorable outcome, such that the long-term growth rate of your bankroll is maximized.
The formula for the Kelly Criterion is:
f = (bp – q) / b
where: f = the fraction of your bankroll to bet b = the decimal odds of the bet (e.g. 2.0 for even money) p = the probability of winning q = the probability of losing (1 – p)
For each round of competition, you would need to determine the decimal odds of each team and calculate the Kelly fraction for each bet, and then bet the calculated amount on the team with the highest Kelly fraction. Repeat this process for each round of competition until one team remains.
It’s important to note that Kelly Criterion assumes you have a long-term edge and may not always produce a profit in the short term. Additionally, betting more than the Kelly fraction may increase the risk of losing your entire bankroll, while betting less than the Kelly fraction may result in a lower potential profit.

The brainteaser was a variation of the 100 coins and 5 pirates. There were 6 pirates instead. So the premise is that there are 6 pirates and you are the captain. You must divide the coins. If 50% of the people rebel against your allocation, they kill you and the process starts again. What is the optimal allocation?

The optimal allocation in this scenario is to give 1 coin to each pirate and keep the rest for yourself. With this allocation, it’s guaranteed that at least 5 pirates will be satisfied and only one pirate can rebel, which means the probability of being killed is only 1/6.
In general, the idea is to keep the number of coins given to each pirate as low as possible while still ensuring that the number of unhappy pirates is minimized. In this way, the risk of a rebellion and the subsequent loss of life is reduced. If you gave 2 coins to each pirate, then 2 of the pirates would be unhappy and the probability of being killed would be much higher.
This allocation also ensures that the total number of coins is maximized, which means that each subsequent allocation will also have a larger pool of coins to divide. This increases the chances of making a successful allocation in the future and prolongs your life as the captain.

Given a sequence consisting of letters and numbers, re-arrange the sequence so that the numbers come together first, while maintaining their initial order in the sequence (not allowed to use additional memory)

Here is one way to rearrange the sequence:
  1. Create two pointers, one for the start of the sequence and one for the end of the sequence.
  2. Move the start pointer forward until you encounter a number.
  3. Move the end pointer backward until you encounter a letter.
  4. Swap the elements at the start and end pointers.
  5. Repeat steps 2 to 4 until the start pointer is greater than the end pointer.
This algorithm takes advantage of the two-pointer technique and ensures that the numbers and letters are separated while maintaining their initial order within each group. The time complexity of this algorithm is O(n), where n is the length of the sequence.

Write C code that would in-place (using O(1) of additional storage) transpose given rectangular matrix of numbers.

Here’s a code that would transpose a rectangular matrix in-place using O(1) of additional storage:
void transpose(int rows, int cols, int matrix[rows][cols]) {
    for (int i = 0; i < rows; i++) {
        for (int j = i + 1; j < cols; j++) {
            int temp = matrix[i][j];
            matrix[i][j] = matrix[j][i];
            matrix[j][i] = temp;
        }
    }
}
This code uses a nested for loop to transpose the matrix. The outer loop i iterates through each row, and the inner loop j iterates through each column. For each iteration, the elements at matrix[i][j] and matrix[j][i] are swapped. This ensures that the elements on the main diagonal remain unchanged and the rest of the elements are transposed.
It’s important to note that this code only works for square matrices (i.e., matrices with an equal number of rows and columns). For non-square matrices, you would need to modify the code to handle the different dimensions.

How are cloud servers different from regular servers?

Cloud servers and regular servers are similar in that they are both computer systems that provide computational resources, but they differ in several key ways:
  1. Physical Location: Regular servers are typically housed in a physical data center or on-premise location, while cloud servers are virtual servers hosted by a cloud provider and can be accessed from anywhere with an internet connection.
  2. Accessibility: Regular servers are accessible only to those with physical access to the data center, while cloud servers can be accessed by authorized users from anywhere in the world.
  3. Scalability: Regular servers may have limited resources, which can limit their ability to handle increased demand. Cloud servers, on the other hand, can be easily scaled up or down to meet changing computational needs.
  4. Maintenance and Upkeep: Regular servers require ongoing maintenance and upkeep, including software and hardware upgrades, security patches, and other tasks. With cloud servers, these responsibilities are typically handled by the cloud provider, freeing up IT resources for other tasks.
  5. Cost: Regular servers can be expensive to purchase, maintain, and upgrade, while cloud servers are typically more cost-effective, as users only pay for the computational resources they consume.
In conclusion, cloud servers offer greater flexibility, scalability, and cost-effectiveness compared to regular servers, making them an increasingly popular choice for businesses of all sizes.

How are virtual functions implemented in C++?

In C++, virtual functions are implemented through the use of virtual tables (also known as vtables) and virtual table pointers (also known as vptrs).
A virtual table is a table of function pointers that is associated with each class that has virtual functions. The virtual table for a class contains the addresses of its virtual functions, and is stored in a single location in memory.
A virtual table pointer is a pointer to the virtual table associated with a class. Every object of a class with virtual functions has a virtual table pointer as a hidden member, which points to the virtual table for that class.
When a virtual function is called on an object, the virtual table pointer for the object is used to access the virtual table and determine the address of the function to be called. If the object is derived from the class with the virtual function, the virtual table for the derived class will contain a different implementation of the function, and that implementation will be called instead.
This mechanism allows the correct implementation of a virtual function to be called based on the dynamic type of the object, rather than its static type, and is the key to the implementation of polymorphism in C++.

Nagarro Solved

Automata Fixing

      

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories