The Number of Full Rounds You Have Played - Problem

You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.

For example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts at 01:30.

You are given two strings loginTime and logoutTime where:

  • loginTime is the time you will login to the game, and
  • logoutTime is the time you will logout from the game.

If logoutTime is earlier than loginTime, this means you have played from loginTime to midnight and from midnight to logoutTime.

Return the number of full chess rounds you have played in the tournament.

Note: All the given times follow the 24-hour clock. That means the first round of the day starts at 00:00 and the last round of the day starts at 23:45.

Input & Output

Example 1 — Basic Same Day
$ Input: loginTime = "09:31", logoutTime = "10:14"
Output: 1
💡 Note: Login at 09:31, can join round starting at 09:45. Round runs 09:45-10:00, which completes before 10:14 logout. Only 1 full round played.
Example 2 — Day Wraparound
$ Input: loginTime = "21:30", logoutTime = "03:00"
Output: 22
💡 Note: Play from 21:30 to midnight (6 rounds: 21:30, 21:45, 22:00, 22:15, 22:30, 22:45, 23:00, 23:15, 23:30, 23:45), then from midnight to 03:00 (12 rounds: 00:00 to 02:45). Total: 10 + 12 = 22 rounds.
Example 3 — Exact Timing
$ Input: loginTime = "00:47", logoutTime = "00:47"
Output: 95
💡 Note: Play almost full day from 00:47 to 00:47 next day. Can't play the round 00:45-01:00 since already started when logging in at 00:47. Can play all other 95 rounds.

Constraints

  • loginTime and logoutTime are in the format "HH:MM"
  • 00 ≤ HH ≤ 23
  • 00 ≤ MM ≤ 59
  • loginTime and logoutTime are different

Visualization

Tap to expand
Chess Tournament Full Rounds Calculator INPUT :00 :15 :30 :45 Login Time: "09:31" Logout Time: "10:14" Rounds every 15 min: :00, :15, :30, :45 ALGORITHM STEPS 1 Convert to Minutes 09:31 = 571 min 10:14 = 614 min 2 Round Login UP 571 --> ceil(571/15)*15 = 585 min (09:45) 3 Round Logout DOWN 614 --> floor(614/15)*15 = 600 min (10:00) 4 Calculate Rounds (600 - 585) / 15 = 15 / 15 = 1 09:31 09:45 10:00 10:14 FINAL RESULT Full Rounds Played: 1 Only 1 complete round: 09:45 - 10:00 Status: OK Key Insight: Round login time UP to next 15-min boundary (to start of a round you can fully play). Round logout time DOWN to previous 15-min boundary (last round you completed). Handle midnight wrap-around by adding 1440 minutes (24 hours) if logout < login. TutorialsPoint - The Number of Full Rounds You Have Played | Optimal Solution
Asked in
Google 15 Amazon 12 Microsoft 8 Apple 6
28.5K Views
Medium Frequency
~15 min Avg. Time
847 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen