Problem Description
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. 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. Return the number of full chess rounds you have played in the tournament.
Key Insights
- Chess rounds start at fixed intervals (every 15 minutes) throughout the day.
- If logoutTime is earlier than loginTime, the gameplay extends to midnight and then resumes until logoutTime.
- We need to determine the number of full rounds played, which requires identifying the rounds that fully encompass the login and logout times.
Space and Time Complexity
Time Complexity: O(1)
Space Complexity: O(1)
Solution
To solve the problem, we need to convert the loginTime
and logoutTime
into minutes from the start of the day. This will allow us to easily calculate the number of rounds played. The steps are as follows:
- Convert both
loginTime
andlogoutTime
into total minutes since midnight. - If
logoutTime
is less thanloginTime
, calculate the rounds played fromloginTime
to midnight and then from midnight tologoutTime
. - Determine the nearest upcoming round start time after
loginTime
and the nearest previous round start time beforelogoutTime
. - Count the number of full rounds between these two times.