Statistics

Problem Statement for "SlowDigitalClock"

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 String currentTime in the form "HH:MM", representing the actual (correct) time at which the clock is mounted on the wall, and a String clockTime also in the form "HH:MM", representing the time the clock is displaying when it is mounted on the wall (the time that we would see if the clock was mounted normally, not upside-down). Assume in both times that the seconds part is 0, i.e., the time just changed to currentTime and the clock just advanced to clockTime. You are to compute the first time after the clock is mounted on the wall that the clock shows the correct time (i.e., the display as shown now that the clock is mounted upside-down represents the correct time) and return this as a String in the form "HH:MM", including any leading zeros. If the clock never shows the correct time, return an empty String.

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

  1. "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).

  2. "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).

  3. "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.

  4. "05:46"

    "23:50"

    240

    Returns: "11:10"

    Be careful when changing days (after 23:59 comes 00:00).

  5. "12:34"

    "23:45"

    197

    Returns: "02:11"

    The first time that the clock displays the correct time may occur after several days.

  6. "12:34"

    "23:45"

    300

    Returns: ""

    In this case, the clock never shows the correct time.

  7. "00:00"

    "00:01"

    86

    Returns: "01:22"

  8. "00:00"

    "01:21"

    77

    Returns: "15:02"

    00:00 01:21 77

  9. "21:28"

    "05:35"

    71

    Returns: "20:50"

  10. "23:04"

    "20:17"

    77

    Returns: ""

  11. "15:19"

    "12:34"

    73

    Returns: ""

  12. "06:49"

    "01:40"

    180

    Returns: ""

  13. "22:15"

    "07:51"

    720

    Returns: ""

  14. "22:08"

    "22:12"

    288

    Returns: ""

  15. "04:18"

    "21:29"

    170

    Returns: ""

  16. "07:43"

    "20:52"

    354

    Returns: ""

  17. "01:32"

    "11:09"

    900

    Returns: ""

  18. "11:07"

    "05:20"

    114

    Returns: ""

  19. "05:00"

    "22:59"

    228

    Returns: ""

  20. "20:46"

    "23:39"

    84

    Returns: ""

  21. "02:32"

    "18:07"

    120

    Returns: ""

  22. "01:51"

    "15:10"

    61

    Returns: "01:51"

  23. "21:10"

    "01:12"

    1000

    Returns: "21:10"

  24. "00:00"

    "00:00"

    123

    Returns: "00:00"

  25. "21:46"

    "18:02"

    437

    Returns: "15:12"

  26. "02:11"

    "09:25"

    516

    Returns: "15:00"

  27. "11:54"

    "10:22"

    78

    Returns: "12:10"

  28. "18:50"

    "01:12"

    236

    Returns: "02:01"

  29. "17:25"

    "04:54"

    322

    Returns: "00:00"

  30. "19:41"

    "18:05"

    239

    Returns: "11:01"

  31. "04:24"

    "14:03"

    842

    Returns: "22:02"

  32. "19:08"

    "00:45"

    681

    Returns: "11:12"

  33. "03:03"

    "11:04"

    311

    Returns: "12:02"

  34. "04:17"

    "17:59"

    624

    Returns: "21:00"

  35. "22:15"

    "11:02"

    793

    Returns: "10:12"

  36. "10:11"

    "02:03"

    470

    Returns: "11:20"

  37. "05:54"

    "02:28"

    874

    Returns: "21:50"

  38. "20:50"

    "19:04"

    574

    Returns: "21:50"

  39. "16:24"

    "17:20"

    569

    Returns: "00:22"

  40. "03:05"

    "15:27"

    224

    Returns: "01:01"

  41. "15:17"

    "11:30"

    122

    Returns: "22:20"

  42. "17:25"

    "00:25"

    461

    Returns: "01:22"

  43. "09:41"

    "22:07"

    476

    Returns: "10:20"

  44. "13:34"

    "16:22"

    956

    Returns: "01:11"

  45. "09:44"

    "02:05"

    669

    Returns: "00:21"

  46. "06:22"

    "18:31"

    687

    Returns: "12:00"

  47. "19:43"

    "13:28"

    64

    Returns: "21:01"

  48. "11:23"

    "23:28"

    266

    Returns: "05:22"

  49. "19:58"

    "18:40"

    250

    Returns: "05:02"

  50. "15:08"

    "13:39"

    617

    Returns: "12:02"

  51. "07:53"

    "19:27"

    669

    Returns: "22:00"

  52. "22:18"

    "12:22"

    999

    Returns: "22:21"

  53. "04:30"

    "20:20"

    121

    Returns: "02:51"

  54. "03:57"

    "21:03"

    903

    Returns: "21:22"

  55. "21:27"

    "14:33"

    912

    Returns: "15:00"

  56. "03:21"

    "21:36"

    248

    Returns: "12:11"

  57. "08:07"

    "14:20"

    854

    Returns: "22:51"

  58. "20:20"

    "06:35"

    690

    Returns: "01:11"

  59. "06:07"

    "13:53"

    382

    Returns: "20:20"

  60. "14:45"

    "00:14"

    747

    Returns: "12:02"

  61. "22:31"

    "06:02"

    505

    Returns: "00:10"

  62. "18:38"

    "06:26"

    539

    Returns: "20:02"

  63. "00:50"

    "22:22"

    191

    Returns: "20:21"

  64. "14:36"

    "07:04"

    773

    Returns: "22:11"

  65. "00:00"

    "00:01"

    86

    Returns: "01:22"

  66. "12:50"

    "05:21"

    125

    Returns: "12:50"

  67. "23:18"

    "03:02"

    997

    Returns: "10:12"

  68. "01:07"

    "02:36"

    77

    Returns: "00:20"

  69. "12:34"

    "23:45"

    300

    Returns: ""

  70. "12:34"

    "23:45"

    197

    Returns: "02:11"

  71. "19:00"

    "17:00"

    807

    Returns: "05:51"

  72. "08:29"

    "22:14"

    532

    Returns: "12:10"

  73. "21:24"

    "11:35"

    441

    Returns: "05:51"

  74. "00:01"

    "00:00"

    73

    Returns: ""

  75. "10:05"

    "00:25"

    737

    Returns: "00:10"

  76. "00:01"

    "00:00"

    71

    Returns: "01:00"

  77. "12:34"

    "23:23"

    61

    Returns: "05:01"

  78. "18:44"

    "09:19"

    922

    Returns: "22:00"

  79. "10:19"

    "02:01"

    999

    Returns: "10:20"

  80. "12:34"

    "23:45"

    358

    Returns: "20:21"

  81. "13:22"

    "11:00"

    61

    Returns: "12:50"

  82. "23:59"

    "00:00"

    120

    Returns: "00:00"

  83. "16:07"

    "01:41"

    321

    Returns: "02:21"

  84. "08:10"

    "13:06"

    922

    Returns: "00:02"

  85. "07:53"

    "18:53"

    362

    Returns: "15:02"

  86. "22:10"

    "11:54"

    358

    Returns: "10:12"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: