Smaller Clock Hand Angle
Updated
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) → doubleExamples
Example 1
hour = 3minutes = 30return = 75.0The minute hand points straight down, at 180 degrees. The hour hand is halfway between three and four, at 105 degrees. The gap between them is seventy-five degrees, so the answer is seventy-five.
Example 2
hour = 12minutes = 0return = 0.0Both hands point straight up at 12, so there is no gap between them. The answer is zero.
Example 3
hour = 1minutes = 57return = 76.5The 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^-5of the exact value are accepted.
More Amazon Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN