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.

- Amit Gupta October 20, 2016 | Flag Reply
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.

- Amit Gupta October 20, 2016 | Flag Reply
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.

- Amit Gupta October 20, 2016 | Flag Reply
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.add(new PricePoint(i, priceStack.MaxQtys[j], priceStack.Prices[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++);
		}
	}

- kredible September 25, 2017 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More