Goldman Sachs Interview Question for Software Engineer / Developers


Country: Singapore
Interview Type: In-Person




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

My idea is -
1. Convert the input to uni-cost graph
2. Find shortest path between two input odes and keep track of the conversation rate of the edges that are part of the shortest path.
3. Multiply the the rates with given amount

- mailchiranjib June 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can think of weighted graph and finding shortest distance between 2 nodes.
Eg:
EUR---(1.2)---> USD ---(0.75)--->GBP---(1.7)--->AUD
| |(90)
|___(150)--->JPY-----(0.60)------>INR

- Nitin December 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It should be unicost graph, in my opinion, since the task is to minimize the number of intermediate conversions.

- itsfight May 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just use dijsktra.

- Anonymous July 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class CurrencyConvert {
	
	public static int getMinimum(ArrayList<Integer> unVisited,float []weight){
		float minimum = Float.MAX_VALUE;
		int position =-1;
		for(int i:unVisited){
			if(weight[i]<minimum){
				minimum=weight[i];
				position =i;
			}
		}
		return position;
	}
	
	public static float myFunction(HashMap<String,Integer> myHashMap,float[][] adMatrix,String source,String destination,int amount){
		ArrayList<Integer> unVisted = new ArrayList<Integer>();
		for(int i=0;i<myHashMap.size();i++){
			unVisted.add(i);
		}
		ArrayList<Integer> visited = new ArrayList<Integer>();
		float weight[] = new float[myHashMap.size()];
		int sourceIndex= myHashMap.get(source);
		for(int i=0;i<weight.length;i++){
			weight[i]=Integer.MAX_VALUE;
		}
		weight[sourceIndex]=1;
		while(!unVisted.isEmpty()){
			int minimumIndex = getMinimum(unVisted,weight);
			for(int i=0;i<adMatrix.length;i++){
				if(adMatrix[minimumIndex][i]!=0 && weight[minimumIndex]*adMatrix[minimumIndex][i]<weight[i] && unVisted.contains(i)){
					weight[i]= weight[minimumIndex]*adMatrix[minimumIndex][i];
				}
			}
			int index = unVisted.indexOf(minimumIndex);
			unVisted.remove(index);
		}
		for(int i=0;i<weight.length;i++){
			System.out.println(weight[i]);
		}
		return weight[myHashMap.get(destination)]*amount;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String nodes ="EUR,USD,GBP,AUD,JPY,INR";
		String [] newlength = nodes.split(",");
		float [][] adMatrix = new float[newlength.length][newlength.length];
		HashMap<String,Integer> myHashMap= new HashMap<>();
		for(int i=0;i<newlength.length;i++){
			myHashMap.put(newlength[i],i);
		}
		List<String> graph = new ArrayList<>();
		String a = "EUR/USD=1.2";
		String b = "USD/GBP=0.75";
		String c = "GBP/AUD=1.7";
		String d = "AUD/JPY=90";
		String e = "GBP/JPY=150";
		String f = "JPY/INR=0.6";
		graph.add(a);
		graph.add(b);
		graph.add(c);
		graph.add(d);
		graph.add(e);
		graph.add(f);
		for(int i=0;i<graph.size();i++){
			String line = graph.get(i);
			String[] equaldivide = line.split("=");
			String[] curr = equaldivide[0].split("/");
			adMatrix[myHashMap.get(curr[0])][myHashMap.get(curr[1])] = Float.parseFloat(equaldivide[1]);
			adMatrix[myHashMap.get(curr[1])][myHashMap.get(curr[0])] = 1/Float.parseFloat(equaldivide[1]);
		}
		String source ="EUR";
		String destination ="INR";
		System.out.println(myFunction(myHashMap,adMatrix,source,destination,100));
	}
}

- Nikhil Attri September 19, 2018 | 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