The Number of Full Rounds You Have Played - Problem

You're participating in an exciting online chess tournament where games run around the clock! ๐Ÿ†

How it works:

  • A new chess round starts every 15 minutes
  • The first round starts at 00:00, then 00:15, 00:30, 00:45, etc.
  • The last round of the day starts at 23:45

Given your loginTime and logoutTime (in 24-hour format), calculate how many complete chess rounds you participated in.

Special case: If logoutTime is earlier than loginTime, it means you played across midnight (from loginTime to 23:59, then from 00:00 to logoutTime).

Goal: Return the total number of full rounds you completed during your gaming session.

Input & Output

example_1.py โ€” Basic Session
$ Input: loginTime = "09:31", logoutTime = "10:14"
โ€บ Output: 1
๐Ÿ’ก Note: You logged in at 09:31 and logged out at 10:14. The only complete round that fits entirely in your session is 09:45-10:00.
example_2.py โ€” Midnight Crossover
$ Input: loginTime = "21:30", logoutTime = "03:00"
โ€บ Output: 22
๐Ÿ’ก Note: You played from 21:30 to midnight, then from midnight to 03:00. Complete rounds: 21:30-21:45, 21:45-22:00, ..., 02:45-03:00 = 22 rounds total.
example_3.py โ€” No Complete Rounds
$ Input: loginTime = "00:47", logoutTime = "00:58"
โ€บ Output: 0
๐Ÿ’ก Note: Your session (00:47 to 00:58) is only 11 minutes long, which doesn't contain any complete 15-minute rounds.

Constraints

  • loginTime and logoutTime are in the format HH:MM
  • loginTime and logoutTime are different times
  • All times follow the 24-hour clock format
  • 0 โ‰ค HH โ‰ค 23, 0 โ‰ค MM โ‰ค 59

Visualization

Tap to expand
Chess Tournament: 24-Hour Timeline00:0006:0012:0018:0024:00Gaming SessionLogin: 09:31Logout: 15:14R109:45R210:00R310:15... (22 total rounds)Algorithm Steps:1. Convert times: Login = 571min (9ร—60+31), Logout = 914min (15ร—60+14)2. Find first round: โŒˆ571/15โŒ‰ ร— 15 = 585min (09:45)3. Find last round: โŒŠ914/15โŒ‹ ร— 15 = 900min (15:00)Result: (900-585)/15 + 1 = 22 complete rounds
Understanding the Visualization
1
Convert to Minutes
Transform HH:MM format to total minutes since midnight
2
Handle Midnight
If logout < login, add 24*60 to logout time
3
Find Boundaries
Calculate first round after login and last round before logout
4
Count Rounds
Calculate difference and divide by 15
Key Takeaway
๐ŸŽฏ Key Insight: Convert everything to minutes and use integer division to find round boundaries - much more efficient than checking each individual round!
Asked in
Amazon 12 Microsoft 8 Google 6 Meta 4
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