Problem Statement
We have a big digital wall clock, but while hanging it on the wall, we mounted it upside-down by mistake (i.e. the display was rotated 180 degrees). To make things worse, the clock has a complicated mechanism inside that makes it go slow when it is upside-down, needing secsPerMinute seconds to advance a minute instead of 60 seconds. Note that even at the moment we hang the clock on the wall, this is not necessarily set at the correct time. The clock itself only displays hours (from 00 to 23) and minutes (from 00 to 59), including any leading zeros.
You are given a
When the clock time is read upside-down, the digits 0, 1, 2, 5 and 8 are the same, 6 is shown as 9 and 9 is shown as 6. The digits 3, 4 and 7 do not show any meaningful digits when read upside-down.
Definition
- Class:
- SlowDigitalClock
- Method:
- firstCorrectTime
- Parameters:
- String, String, int
- Returns:
- String
- Method signature:
- String firstCorrectTime(String currentTime, String clockTime, int secsPerMinute)
- (be sure your method is public)
Notes
- You may assume that when the clock display is updated to the next minute, this update takes zero time.
Constraints
- currentTime and clockTime will have exactly 5 characters each, in the form "HH:MM". "HH" will be an integer between 00 and 23, inclusive (including any leading zeros), "MM" will be an integer between 00 and 59, inclusive (including any leading zeros).
- secsPerMinute will be between 61 and 1000, inclusive.
Examples
"01:11"
"21:09"
61
Returns: "01:12"
At the beginning, the clock shows the upside-down time "60:12" (of course, this is not a valid time, so this can not be the correct time). After 61 seconds, the clock will advance to 21:10, which is read upside-down as: 01:12. Since the correct time at the beginning was 01:11:00, now (61 seconds later) the time is 01:12:01, so (ignoring the seconds) the clock shows the correct time "01:12". The figure below shows the normal clock display when it shows 21:10. The figure below shows the same display upside-down (now showing 01:12).
"01:10"
"21:09"
61
Returns: "01:12"
In 120 seconds, the time is 01:12, but the clock still shows 21:10 (which upside-down reads 01:12).
"12:50"
"05:21"
125
Returns: "12:50"
The clock already shows the correct time at the beginning (and this remains correct for the next 60 seconds), so currentTime is returned.
"05:46"
"23:50"
240
Returns: "11:10"
Be careful when changing days (after 23:59 comes 00:00).
"12:34"
"23:45"
197
Returns: "02:11"
The first time that the clock displays the correct time may occur after several days.
"12:34"
"23:45"
300
Returns: ""
In this case, the clock never shows the correct time.
"00:00"
"00:01"
86
Returns: "01:22"
"00:00"
"01:21"
77
Returns: "15:02"
00:00 01:21 77
"21:28"
"05:35"
71
Returns: "20:50"
"23:04"
"20:17"
77
Returns: ""
"15:19"
"12:34"
73
Returns: ""
"06:49"
"01:40"
180
Returns: ""
"22:15"
"07:51"
720
Returns: ""
"22:08"
"22:12"
288
Returns: ""
"04:18"
"21:29"
170
Returns: ""
"07:43"
"20:52"
354
Returns: ""
"01:32"
"11:09"
900
Returns: ""
"11:07"
"05:20"
114
Returns: ""
"05:00"
"22:59"
228
Returns: ""
"20:46"
"23:39"
84
Returns: ""
"02:32"
"18:07"
120
Returns: ""
"01:51"
"15:10"
61
Returns: "01:51"
"21:10"
"01:12"
1000
Returns: "21:10"
"00:00"
"00:00"
123
Returns: "00:00"
"21:46"
"18:02"
437
Returns: "15:12"
"02:11"
"09:25"
516
Returns: "15:00"
"11:54"
"10:22"
78
Returns: "12:10"
"18:50"
"01:12"
236
Returns: "02:01"
"17:25"
"04:54"
322
Returns: "00:00"
"19:41"
"18:05"
239
Returns: "11:01"
"04:24"
"14:03"
842
Returns: "22:02"
"19:08"
"00:45"
681
Returns: "11:12"
"03:03"
"11:04"
311
Returns: "12:02"
"04:17"
"17:59"
624
Returns: "21:00"
"22:15"
"11:02"
793
Returns: "10:12"
"10:11"
"02:03"
470
Returns: "11:20"
"05:54"
"02:28"
874
Returns: "21:50"
"20:50"
"19:04"
574
Returns: "21:50"
"16:24"
"17:20"
569
Returns: "00:22"
"03:05"
"15:27"
224
Returns: "01:01"
"15:17"
"11:30"
122
Returns: "22:20"
"17:25"
"00:25"
461
Returns: "01:22"
"09:41"
"22:07"
476
Returns: "10:20"
"13:34"
"16:22"
956
Returns: "01:11"
"09:44"
"02:05"
669
Returns: "00:21"
"06:22"
"18:31"
687
Returns: "12:00"
"19:43"
"13:28"
64
Returns: "21:01"
"11:23"
"23:28"
266
Returns: "05:22"
"19:58"
"18:40"
250
Returns: "05:02"
"15:08"
"13:39"
617
Returns: "12:02"
"07:53"
"19:27"
669
Returns: "22:00"
"22:18"
"12:22"
999
Returns: "22:21"
"04:30"
"20:20"
121
Returns: "02:51"
"03:57"
"21:03"
903
Returns: "21:22"
"21:27"
"14:33"
912
Returns: "15:00"
"03:21"
"21:36"
248
Returns: "12:11"
"08:07"
"14:20"
854
Returns: "22:51"
"20:20"
"06:35"
690
Returns: "01:11"
"06:07"
"13:53"
382
Returns: "20:20"
"14:45"
"00:14"
747
Returns: "12:02"
"22:31"
"06:02"
505
Returns: "00:10"
"18:38"
"06:26"
539
Returns: "20:02"
"00:50"
"22:22"
191
Returns: "20:21"
"14:36"
"07:04"
773
Returns: "22:11"
"00:00"
"00:01"
86
Returns: "01:22"
"12:50"
"05:21"
125
Returns: "12:50"
"23:18"
"03:02"
997
Returns: "10:12"
"01:07"
"02:36"
77
Returns: "00:20"
"12:34"
"23:45"
300
Returns: ""
"12:34"
"23:45"
197
Returns: "02:11"
"19:00"
"17:00"
807
Returns: "05:51"
"08:29"
"22:14"
532
Returns: "12:10"
"21:24"
"11:35"
441
Returns: "05:51"
"00:01"
"00:00"
73
Returns: ""
"10:05"
"00:25"
737
Returns: "00:10"
"00:01"
"00:00"
71
Returns: "01:00"
"12:34"
"23:23"
61
Returns: "05:01"
"18:44"
"09:19"
922
Returns: "22:00"
"10:19"
"02:01"
999
Returns: "10:20"
"12:34"
"23:45"
358
Returns: "20:21"
"13:22"
"11:00"
61
Returns: "12:50"
"23:59"
"00:00"
120
Returns: "00:00"
"16:07"
"01:41"
321
Returns: "02:21"
"08:10"
"13:06"
922
Returns: "00:02"
"07:53"
"18:53"
362
Returns: "15:02"
"22:10"
"11:54"
358
Returns: "10:12"