Amazon Interview Question for Software Engineer / Developers






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

double angle_in_degree(int hours,int minutes)
{
double value = ((720+(hours%12)*60 - minutes*11)%(720))/2;
return value>180 ? 360-value: value;
}

- strezh October 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

some corrects
double angle_in_degree(int hours,int minutes)
{
double value = double((720+(hours%12)*60 - minutes*11)%(720))/2;
return value>180 ? 360-value: value;
}

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

same solution in simplest variant by using modulus function fabs() from <math.h>:

#include <math.h>
double angle_in_degree(int hours,int minutes)
{
double value = fabs((hours%12)*30 - minutes*5.5);
return value>180 ? 360-value: value;
}

- strezh October 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

anyways, this was my answer:
Given 'hr' hours and 'min' minutes, angle = modulus( 0.5*(60*hr-11*min) )

- chennavarri October 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think that angle must be <= 180 degree, i.e. for 1:40 -> 170 degree, but not 190.

(and also hours may be in 24h format)

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

I shud have mentioned that.. its in 12 hr format since it is analog clock. so 12:00 angle wud be 360 which is accepted as 0. so 190 is accepted as 170

- chennavarri October 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose 0<=hour<12, 0<=min<60
var d = Math.Abs((30*hour + min/2 - 6*min));
if(m%2==0)
return d.ToString() + " degrees";
return d.ToString() + " degrees 30 minutes";

30*hour comes from the hour that has 30 degrees.
6*min comes from minutes because a minute has 6 degrees.
min/2 comes from the fact that the hour hand is moved towards next hour. if min is even, we don't have any minutes in the result. if the min is odd, we have 30 minutes in the result...

- S October 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Clock {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(getAngle(2,11));

	}
	
	public static double getAngle(int hours, int mins) {
		System.out.println(hours * 30.0 + 30.0*mins/60.0);
		System.out.println(mins*360/60);
		
		double angle = Math.abs((hours * 30 + 30.0*mins/60.0) - (mins*360.0/60.0));
		return angle;
		
	}
	

}

- HSJ October 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An hour hand takes 12hrs to cover 360 degrees
Therefore in 1hr->30 and 1min->0.5

A minute hand takes 60 mins to cover 360 degrees
Therefore 1min-> 6 degrees

So the function to calculate angle with 12 hours clock is

degree between hour and minute hand =

30h + 0.5m - 6m

The first term represents the angle covered by hour hand and the second term represents the additional coverage after 'm' minutes and third term represents the angle covered by minute hand

- Anonymous November 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An hour hand takes 12hrs to cover 360 degrees
Therefore in 1hr->30 and 1min->0.5

A minute hand takes 60 mins to cover 360 degrees
Therefore 1min-> 6 degrees

So the function to calculate angle with 12 hours clock is

degree between hour and minute hand =

30h + 0.5m - 6m

The first term represents the angle covered by hour hand and the second term represents the additional coverage after 'm' minutes and third term represents the angle covered by minute hand

- ketz November 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

stackoverflow.com/questions/2748965/interview-q-find-angle-between-hour-and-minute-hands-in-an-analog-clock

- Dilbert Einstein August 20, 2012 | 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