Goldman Sachs Interview Question for Software Engineer / Developers






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

return angle?

- Anonymous October 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int angle = Math.abs((hours*30 + minutes*30/60 - minutes *6);

- Anonymous October 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@2nd Anonymous
You seem to be headed in the right direction.
@Ashis
Also understand that the hour hand may not necessarily point perfectly to number markings. It may also be in between two number markings. So we also need to include an additionally small angle as well eg- Check the hour hand at time 2.30 or so. Its in between 2 & 3

Hour hand needs to progress 30 degrees in a span of 60 minutes.
So as one of the answers above Math.abs((hours*30+minutes*(30/60))-minutes*6)
Please advise

- amit November 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the angle found can be obtuse at times (greater than 90 but less than 180). They should have ideally asked about smallest angle formed between clock hands.

- mumbojumbo November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int clock(int hours, int min){
int angle = 0;
int d_hours = (1/12*hours)+(5*hours);
if(d_hours<min){angle = min-d_hours;}
else{angle=d_hours-min;}
return angle;
}

- noob February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

correction:
d_hours=(1/12*min)+(5*hours);

- noob February 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are right. But didn't you forget you need to times the angle.

public static double clock(int hours, int minutes){
int minAngle = 360 / 60; // 6
double p = 5.0 / 60 * minutes;
double hourAngle = 360/12; // 30
double h = hours * hourAngle + p * minAngle;
int m = minutes * minAngle;
return Math.abs(h -m - 360);
}

- Kevin March 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what does the 5 mean here? double p = 5.0 / 60 * minutes;

- yesme March 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

5 is number of walks for the hour hand to run from let say from 10 to 11. So it is proportional to the minutes which is 60 walks.

when you use this 5.0/60 * minutes * 6, you should get the hour hand angle respectively with the minutes.

- Kevin Ou March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
* Goldman Sachs:
* Write a method to calculate the acute angle between a clock
*/

public class Clock{
public static void main(String args[]){
long hours = 3;
long minutes = 15;
// Angle made by the hour hand in hours and minutes
long angle_hour = 30* hours;
double angle_Min_hour = 0.5*minutes;
long mins = 6 * minutes;
System.out.println(angle_hour+":"+angle_Min_hour+":"+mins);
System.out.println("Diff:"+((angle_hour+angle_Min_hour)-mins));
}
}

- TTYL March 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

example to understand the above code better:

If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands? (The answer to this is not zero!)
Hour Hand : 12 Hours = 360
1 Hour = 360/12= 30 Degrees.
3 Hours = 3*30 = 90 Degrees.
15 Min = 30/60*15 = 7.5 Degrees.
Therefore, total angle covered by Hour Hand is := 90+7.5 = 97.5
Minuted Hand: 60 Min = 360
1 Min = 6 Degree
Therefore 15 Min = 15*6 = 90 Degree
The net difference is = 97.5-90= 7.5 Degrees.

- Anonymous March 10, 2010 | 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