Epic Systems Interview Question for Software Engineer / Developers


Country: United States




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

public class HourMinute {

	public static void main(String[] args)
	{
		String time = "12:15";
		String[] splitTime=time.split(":");
		double angle=calculateAngle(Integer.parseInt(splitTime[0]),Integer.parseInt(splitTime[1]));
		System.out.println("Angle when time is "+time+" : "+angle);
	}
	
	public static double  calculateAngle(int hh,int mm)
	{
		double angle=Math.abs(mm*6-(hh*30+mm*0.5));
		if(angle>180)
			return 360-angle;
		return angle;
		
	}
	
}

- AI October 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

angle = ( hour * 30 ) +  (min * 0.5 )   -  ( min  * 6 )

Each hour = 30 degrees
Each minute = 5 degrees
The hour hand also moves 0.5 degrees per minute

- AD October 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You may want to reverse the subtraction depending on the direction used for calculating the angle.

- AD October 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Aha! A simplification

angle = ( hour * 30 ) +  (min * 0.5    -   min  * 6 )
==>
angle = ( hour * 30 ) +    -   (min  * 5 .5)

- AD October 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class clock_angle {
public static void main(String args[])
{
System.out.println("angle swapped:> "+calculate("02:23"));
System.out.println("angle swapped:> "+calculate("03:15"));
System.out.println("angle swapped:> "+calculate("03:30"));
}
static Integer calculate(String time)
{   int angle = 0;
	int degree_min=360/60;
	int degree_hour=360/12;
	String str=time+"";
	String a=str.substring(0,2);
	String b=str.substring(3,5);
	int i = Integer.parseInt(a.substring(0));
	int j = Integer.parseInt(b.substring(0));
	int hour_degree_swapped=i*degree_hour;
	int min_degree_swapped=j*degree_min;
	if(hour_degree_swapped>min_degree_swapped)
	{
		angle=hour_degree_swapped-min_degree_swapped;
		}
	else if(hour_degree_swapped<min_degree_swapped)
	{
		angle=min_degree_swapped-hour_degree_swapped;
		}
	else if(hour_degree_swapped==min_degree_swapped)
	{angle=0;
	}
	return angle;
	
}
}

- Davi_singh November 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// please see modified solution of above solution for accurate answer

public class clock_angle {
public static void main(String args[])
{
System.out.println("angle swapped:> "+calculate("02:23"));
System.out.println("angle swapped:> "+calculate("03:15"));
System.out.println("angle swapped:> "+calculate("03:30"));
}
static Integer calculate(String time)
{   int angle = 0;
	int degree_min=360/60;
	int degree_hour=360/12;
	String str=time+"";
	String a=str.substring(0,2);
	String b=str.substring(3,5);
	int i = Integer.parseInt(a.substring(0));
	int j = Integer.parseInt(b.substring(0));
	int hour_degree_swapped=(i*degree_hour)+(degree_hour*j/60);
	int min_degree_swapped=j*degree_min;
	angle=Math.abs(hour_degree_swapped-min_degree_swapped);
	return angle;
	
}
}

- Davi_singh November 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

'''
Get the angle between hour and minute hands, given time
Angle must be < 180
'''

def get_angle(hh, mm):
	mm = float(mm)
	hh_angle_from_zero = (hh + (mm / 60)) * 30
	mm_angle_from_zero = mm * 6 # which is short form for -> mm/60 * 360
	
	diff = abs(hh_angle_from_zero - mm_angle_from_zero) % 180
	
	return diff

print (get_angle(0,0)) # 0
print (get_angle(2,30)) # 105
print (get_angle(6,30)) # 15
print (get_angle(11,30)) # 165

- dbhage November 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

return min(abs(30*hour - 5.5*min), 360 - abs(30*hour - 5.5*min));

3rd grade math.

- XiaoPiGu December 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, you are.

- realhire December 12, 2014 | Flag


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