Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Coding: Angle Between Clock Hands

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Coding: Angle Between Clock Hands. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Decimal Point Analytics dashboards may display timestamps in either 12-hour or 24-hour format. Given an hour, minute, and second, calculate the smaller angle between the analog clock's hour and minute hands.

Both hands move continuously. The hour hand advances during each minute and second, while the minute hand advances during each second. Treat hour 0 and hour 12 as the same clock position.

Formal Specification

Implement clock_angle(hour, minute, second).

  • Input: Three integers: hour in the range 0 through 23, minute in the range 0 through 59, and second in the range 0 through 59.
  • Output: A floating-point number representing the smaller angle in degrees, rounded to at most six decimal places. The result must be in the inclusive range [0, 180].

Constraints

  • 0 <= hour <= 23
  • 0 <= minute <= 59
  • 0 <= second <= 59
  • The input represents a valid time
  • Return the smaller angle in the range [0, 180]

Function Signature

def clock_angle(hour, minute, second):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output