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:00", logoutTime = "23:59"
Output: 95
💡 Note: Play almost full day from 00:00 to 23:59. Last complete round starts at 23:45 and ends at 00:00. Total rounds from 00:00 to 23:45 = 96, but last round at 23:45 doesn't complete before 23:59, so 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: 15-Minute Rounds09:30-09:4509:45-10:0010:00-10:1510:15-10:3010:30-10:45Before loginRound 1Round 2Round 3After logoutLogin: 09:31Logout: 10:14Login after first round started, logout before last round endsCan play complete rounds: 09:45-10:00Output: 1 full round
Understanding the Visualization
1
Input
Two time strings: loginTime and logoutTime in HH:MM format
2
Process
Count complete 15-minute rounds between these times
3
Output
Number of full rounds that can be played
Key Takeaway
🎯 Key Insight: Convert times to minutes and use division to count 15-minute intervals efficiently
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