TopCoder problem "FussySleeper" used in TCHS SRM 8 (Division I Level One)

Problem Statement

    Last night, after that terrible nightmare about pink elephants, you decided that you would never again go to sleep unless the time showing on your digital clock was a multiple of the number of elephants in your dream. Rather than waiting and constantly checking the clock, you decide to calculate the earliest time after the current time that you can go to sleep. Write a method which takes the currentTime on your clock, and the number of elephants in your dream, and returns the earliest future time that is a multiple of elephants.

currentTime will be a int[] containing exactly two elements. The first element is the current hour value on the clock (between 0 and 23, inclusive), and the second element is the current minute (between 0 and 59, inclusive). The returned int[] must also follow this format.

The time on the clock is a multiple of some number k whenever the digits on the clock form a four-digit number ('HHMM') which is divisible by k - for example 10:01 is divisible by 11 (1001 = 11 * 91), but 01:04 is not divisible by 7 (104 = 14 * 7 + 6). Even if you can fall asleep at the current time, you must return the next time you can fall asleep.


Parameters:int[], int
Method signature:int[] nextTime(int[] currentTime, int elephants)
(be sure your method is public)


-currentTime will be as described in the statement.
-elephants will be between 1 and 1000, inclusive.


{21, 30}
Returns: {22, 0 }
You are able to sleep at the top of every hour. The earliest future time that satisfies this requirement is 22:00 (2200 = 22 x 100).
{20, 30}
Returns: {20, 47 }
You just missed your chance to sleep at 20:24 (2024 = 23 x 88) but your next chance is at 20:47
Returns: {23, 56 }
With only one elephant, you can sleep every minute, so the next possible time is 23:56
{0, 0}
Returns: {0, 0 }
With so many elephants in your dream, the only time you can sleep is at midnight. Although you can't sleep currently, you will be able to the next time the clock hits "00:00".

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration