FastPrepSmaller Clock Hand Angle

Smaller Clock Hand Angle

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an analog-clock time with integer hour and minutes, return the smaller angle in degrees between the hour hand and the minute hand.

The hour hand moves continuously as the minutes advance. The answer is in the inclusive range [0, 180].

Function

clockAngle(hour: int, minutes: int) → double

Examples

Example 1

hour = 3minutes = 30return = 75.0

The minute hand is at 180 degrees and the hour hand is at 105 degrees.

Example 2

hour = 12minutes = 0return = 0.0

Both hands point to 12.

Example 3

hour = 1minutes = 57return = 76.5

The direct difference is 283.5 degrees, so the smaller angle is 360 - 283.5 = 76.5 degrees.

Constraints

  • 1 <= hour <= 12.
  • 0 <= minutes <= 59.
  • Answers within 10^-5 of the exact value are accepted.

More Amazon problems

See Amazon hiring insights
public double clockAngle(int hour, int minutes) {
    // Write your code here.
}
hour3
minutes30
expected75.0
Checking account…