## Goldman Sachs Interview Question for Software Engineer / Developers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
0
of 0 vote

We can implement this scenario with an observer pattern. The observed object taking in the number of stocks to be bought. The same object will also maintain a list of observers (the exchanges so to say). As soon as the observed object receives a buy order of say n stocks, it will notify all observers (stock exchanges), which in return will return the best selling price from them. This price can be compared at the observed object's end and the first order can be executed at the exchange offering the best selling (lowest) price. Do this recursively for n number of orders and your entire buy order will be executed at the lowest price. You can perform the same scenario for a sell order of n stocks as well.

Comment hidden because of low score. Click to expand.
0
of 0 vote

We can implement this scenario with an observer pattern. The observed object taking in the number of stocks to be bought. The same object will also maintain a list of observers (the exchanges so to say). As soon as the observed object receives a buy order of say n stocks, it will notify all observers (stock exchanges), which in return will return the best selling price from them. This price can be compared at the observed object's end and the first order can be executed at the exchange offering the best selling (lowest) price. Do this recursively for n number of orders and your entire buy order will be executed at the lowest price. You can perform the same scenario for a sell order of n stocks as well.

Comment hidden because of low score. Click to expand.
0
of 0 vote

We can implement this scenario with an observer pattern. The observed object taking in the number of stocks to be bought. The same object will also maintain a list of observers (the exchanges so to say). As soon as the observed object receives a buy order of say n stocks, it will notify all observers (stock exchanges), which in return will return the best selling price from them. This price can be compared at the observed object's end and the first order can be executed at the exchange offering the best selling (lowest) price. Do this recursively for n number of orders and your entire buy order will be executed at the lowest price. You can perform the same scenario for a sell order of n stocks as well.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose we could take a snapshot of the current prices across the exchanges and capture them in the following format:

``````public class MarketSnapshot {
public PriceStack[] PriceStacks;
}

public class PriceStack {
public int[] MaxQtys;
public double[] Prices;
}``````

Then, we construct an increasing sequence of prices points as follows:

``````public class PricePoint {
public int Exchange;
public int MaxQty;
public double Price;
}

private static List<PricePoint> getSortedPricePoints(MarketSnapshot snapshot) {
List<PricePoint> pricePoints = new ArrayList<PricePoint>();
for(int i=0; i < snapshot.PriceStacks.length; i++) {
PriceStack priceStack = snapshot.PricePoints[i];
for (int j=0; j < priceStack.Prices.length; j++) {
}
}
pricePoints.sort((p1, p2) -> p1.Price.compareTo(p2.Price));
return pricePoints;
}``````

Then we simply buy starting from the left hand side of this list, until we have bought enough quantity:

``````private static void buyAtMarket(int qty, MarketSnapshot currentSnapshot) {
List<PricePoint> pricePoints = getSortedPricePoints(currentSnapshot);
int bought = 0;
int i = 0;
while(bought < qty && i < pricePoints.size()) {
bought += pricePoints.get(i++);
}
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.