TopcoderArchiveVisit Topcoder
SRM25 May 2011
SRM 515

RotatedClock

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
RotatedClock
Method:
getEarliest
Parameters:
int, int
Returns:
String
Method signature:
String getEarliest(int hourHand, int minuteHand)
(be sure your method is public)

Constraints

  • hourHand and minuteHand will each be between 0 and 359, inclusive.

Examples

  1. 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:
  2. 90
    120
    Returns: "11:00"
  3. 240
    36
    Returns: ""
  4. 19
    19
    Returns: ""
  5. 1
    12
    Returns: "00:02"
    The time when the coding phase started.
Back to all problems