Statistics

Problem Statement for "AmbiguousWatch"

Problem Statement

You have a watch with only an hour hand and a minute hand. The watch is a round 12-hour watch. Both hands move continuously. Both hands have the same length and are indistinguishable, so at certain moments, the time displayed is ambiguous. A time is considered ambiguous if there exists a different time at which the hands appear to have the same positions. For example, the time moment on the picture is ambiguous. At this moment, you would not be able to tell if it was a little past 00:05, or a little past 01:00.

You are given two times in the form "HH:MM" (quotes for clarity), where 00 <= HH < 12, and 00 <= MM < 60. Return the number of ambiguous moments between startTime and finishTime, inclusive. The times represented by startTime and finishTime are in the same half of the day.

Definition

Class:
AmbiguousWatch
Method:
howMany
Parameters:
String, String
Returns:
int
Method signature:
int howMany(String startTime, String finishTime)
(be sure your method is public)

Constraints

  • startTime and finishTime will have the form "HH:MM" (quotes for clarity), where 00 <= HH < 12, 00 <= MM < 60.
  • startTime must be earlier than or the same as finishTime (in the same half of the day).

Examples

  1. "00:00"

    "00:00"

    Returns: 0

    This moment is not ambiguous.

  2. "00:05"

    "00:06"

    Returns: 1

    There is one ambiguous moment in this time range. At that moment, you would not be able to tell if it was a little past 00:05, or a little past 01:00.

  3. "00:00"

    "01:00"

    Returns: 11

  4. "00:00"

    "11:59"

    Returns: 132

  5. "03:21"

    "10:54"

    Returns: 84

  6. "00:00"

    "00:22"

    Returns: 4

  7. "02:25"

    "10:19"

    Returns: 87

  8. "03:16"

    "08:03"

    Returns: 52

  9. "01:56"

    "03:49"

    Returns: 20

  10. "04:28"

    "05:06"

    Returns: 7

  11. "00:59"

    "05:41"

    Returns: 51

  12. "00:50"

    "10:05"

    Returns: 102

  13. "00:43"

    "03:31"

    Returns: 30

  14. "04:24"

    "11:00"

    Returns: 73

  15. "03:56"

    "09:17"

    Returns: 59

  16. "08:22"

    "10:07"

    Returns: 19

  17. "03:40"

    "08:36"

    Returns: 55

  18. "01:57"

    "03:57"

    Returns: 22

  19. "02:57"

    "05:35"

    Returns: 28

  20. "03:20"

    "09:54"

    Returns: 72

  21. "01:47"

    "05:46"

    Returns: 43

  22. "03:26"

    "10:29"

    Returns: 78

  23. "09:16"

    "11:43"

    Returns: 27

  24. "05:54"

    "10:39"

    Returns: 52

  25. "00:14"

    "09:55"

    Returns: 107

  26. "01:41"

    "01:43"

    Returns: 0

  27. "00:15"

    "06:00"

    Returns: 64

  28. "00:06"

    "07:06"

    Returns: 77

  29. "07:48"

    "09:17"

    Returns: 17

  30. "08:29"

    "09:14"

    Returns: 8

  31. "02:28"

    "06:41"

    Returns: 46

  32. "07:06"

    "08:10"

    Returns: 12

  33. "07:43"

    "11:27"

    Returns: 42

  34. "02:55"

    "11:58"

    Returns: 100

  35. "03:32"

    "08:06"

    Returns: 50

  36. "01:01"

    "09:16"

    Returns: 90

  37. "05:56"

    "10:34"

    Returns: 51

  38. "06:07"

    "06:52"

    Returns: 8

  39. "08:13"

    "11:26"

    Returns: 36

  40. "00:05"

    "04:03"

    Returns: 45

  41. "08:27"

    "11:52"

    Returns: 38

  42. "08:59"

    "09:17"

    Returns: 3

  43. "01:43"

    "02:22"

    Returns: 7

  44. "09:24"

    "10:57"

    Returns: 16

  45. "07:04"

    "10:22"

    Returns: 36

  46. "03:27"

    "08:16"

    Returns: 53

  47. "01:07"

    "07:32"

    Returns: 71

  48. "03:21"

    "10:31"

    Returns: 80

  49. "01:56"

    "03:16"

    Returns: 14

  50. "06:31"

    "11:31"

    Returns: 55

  51. "01:53"

    "02:05"

    Returns: 2

  52. "02:07"

    "03:13"

    Returns: 12

  53. "05:58"

    "06:55"

    Returns: 10

  54. "01:52"

    "03:25"

    Returns: 16

  55. "07:19"

    "08:52"

    Returns: 16

  56. "00:57"

    "08:57"

    Returns: 87

  57. "00:43"

    "00:54"

    Returns: 2

  58. "01:16"

    "09:32"

    Returns: 91

  59. "04:34"

    "09:40"

    Returns: 57

  60. "05:14"

    "07:20"

    Returns: 23

  61. "05:55"

    "08:53"

    Returns: 32

  62. "04:05"

    "09:49"

    Returns: 63

  63. "01:41"

    "09:48"

    Returns: 89

  64. "00:48"

    "01:07"

    Returns: 3

  65. "00:43"

    "02:19"

    Returns: 17

  66. "02:43"

    "08:04"

    Returns: 59

  67. "03:03"

    "06:50"

    Returns: 41

  68. "04:23"

    "10:02"

    Returns: 62

  69. "03:46"

    "03:46"

    Returns: 0

  70. "07:52"

    "08:18"

    Returns: 5

  71. "03:49"

    "10:50"

    Returns: 78

  72. "03:33"

    "05:44"

    Returns: 24

  73. "08:53"

    "09:12"

    Returns: 4

  74. "06:37"

    "08:40"

    Returns: 24

  75. "04:56"

    "06:30"

    Returns: 18

  76. "07:08"

    "10:33"

    Returns: 37

  77. "01:20"

    "08:01"

    Returns: 74

  78. "04:50"

    "05:39"

    Returns: 9

  79. "00:38"

    "01:22"

    Returns: 8

  80. "06:35"

    "08:04"

    Returns: 17

  81. "00:58"

    "11:03"

    Returns: 110

  82. "08:10"

    "10:03"

    Returns: 20

  83. "03:19"

    "11:07"

    Returns: 86

  84. "08:24"

    "08:48"

    Returns: 3

  85. "05:59"

    "07:57"

    Returns: 21

  86. "01:40"

    "01:41"

    Returns: 1

  87. "01:00"

    "01:00"

    Returns: 0

  88. "02:00"

    "04:13"

    Returns: 25

  89. "05:00"

    "10:10"

    Returns: 57

  90. "00:00"

    "10:00"

    Returns: 110

  91. "00:00"

    "10:30"

    Returns: 116

  92. "00:00"

    "11:59"

    Returns: 132

  93. "05:30"

    "05:59"

    Returns: 6

  94. "00:34"

    "11:09"

    Returns: 116

  95. "02:00"

    "11:59"

    Returns: 110

  96. "10:20"

    "10:59"

    Returns: 6

  97. "08:06"

    "08:52"

    Returns: 8

  98. "00:59"

    "11:00"

    Returns: 110

  99. "11:05"

    "11:06"

    Returns: 0

  100. "03:12"

    "10:59"

    Returns: 84

  101. "00:22"

    "11:57"

    Returns: 128

  102. "00:00"

    "11:55"

    Returns: 132

  103. "00:06"

    "09:37"

    Returns: 105

  104. "06:00"

    "11:21"

    Returns: 59

  105. "00:06"

    "11:59"

    Returns: 131

  106. "00:05"

    "11:59"

    Returns: 132

  107. "00:00"

    "01:00"

    Returns: 11


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: