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, then00: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
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!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code