Connection Status:
Competition Arena > RotatedClock
SRM 515 · 2011-05-25 · by lyrically · Brute Force, Simple Math
Class Name: RotatedClock
Return Type: String
Method Name: getEarliest
Arg Types: (int, int)
Problem Statement

Problem Statement

Lecette has a clock with an hour hand and a minute hand. The hour hand makes a full rotation in 12 hours, and the minute hand makes a full rotation in one hour. Both hands move smoothly, at constant speeds. The clock has a scale marked in 30 degree increments, and both hands point to the same mark at 00:00.

Lecette wants to know what time it is, but the clock is rotated, so she can't tell where the top of the clock is. She measured the angles of hands from a certain mark, clockwise: hourHand and minuteHand (both in degrees). Return the earliest possible time that is consistent with these measurements. Format the return value as a String of the form "HH:MM" (quotes for clarity). Lecette might have measured the angles incorrectly. If there is no corresponding time, return an empty String instead.

Constraints

  • hourHand and minuteHand will each be between 0 and 359, inclusive.
Examples
0)
70
300
Returns: "08:20"

This is how the clock were positioned when Lecette made her measurements: In order to show a valid time, the clock needs to be turned upside down:

1)
90
120
Returns: "11:00"
2)
240
36
Returns: ""
3)
19
19
Returns: ""
4)
1
12
Returns: "00:02"

The time when the coding phase started.

Submissions are judged against all 115 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class RotatedClock with a public method string getEarliest(int hourHand, int minuteHand) · 115 test cases · 2 s / 256 MB per case

Submitting as anonymous