Skip to main content

The Number of Full Rounds You Have Played - Solution & Explanation

MediumMathString18 min readAsked at: Microsoft
Practice this problem

Problem Statement

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.

 

Example 1:

Input: loginTime = "09:31", logoutTime = "10:14"
Output: 1
Explanation: You played one full round from 09:45 to 10:00.
You did not play the full round from 09:30 to 09:45 because you logged in at 09:31 after it began.
You did not play the full round from 10:00 to 10:15 because you logged out at 10:14 before it ended.

Example 2:

Input: loginTime = "21:30", logoutTime = "03:00"
Output: 22
Explanation: You played 10 full rounds from 21:30 to 00:00 and 12 full rounds from 00:00 to 03:00.
10 + 12 = 22.

 

Constraints:

  • loginTime and logoutTime are in the format hh:mm.
  • 00 <= hh <= 23
  • 00 <= mm <= 59
  • loginTime and logoutTime are not equal.

Approach Overview

Problem Overview: You receive two timestamps in HH:MM format representing when a player logged in and logged out. A game round lasts exactly 15 minutes. The task is to count how many complete 15‑minute rounds were fully played between those two times. If the logout time is earlier than the login time, the session crossed midnight and continues into the next day.

Approach 1: Convert Times to Minutes and Calculate (Time: O(1), Space: O(1))

The straightforward strategy converts both timestamps into total minutes from midnight. Parse the string, compute hours * 60 + minutes, and handle overnight sessions by adding 24 * 60 minutes when the logout time is smaller than the login time. Once both values are normalized, round the start time up to the next 15‑minute boundary and round the end time down to the previous boundary. The number of full rounds equals (endRounded - startRounded) / 15 if the result is positive.

This approach works because a valid round must start and end exactly on multiples of 15 minutes. By shifting the login time upward and the logout time downward, only fully completed rounds remain in the interval. The implementation mainly uses simple arithmetic and string parsing, which makes it easy to implement in any language. Problems like this rely heavily on math operations combined with basic string parsing.

Approach 2: Utilize Modulo for Round Calculation (Time: O(1), Space: O(1))

This version performs the same logic but uses modulo arithmetic to align timestamps to valid round boundaries. After converting both times to minutes, adjust the login time using (15 - start % 15) % 15 to move it to the next multiple of 15. Adjust the logout time using end - (end % 15) to snap it to the previous boundary. Handle the overnight case by adding 1440 minutes when the logout time occurs the next day.

Once aligned, compute the difference and divide by 15 to get the total rounds. The modulo trick removes conditional rounding logic and keeps the calculation concise. This method is often preferred in interviews because it shows comfort with arithmetic transformations and edge cases such as midnight wrap‑around.

Recommended for interviews: Interviewers typically expect the minute‑conversion strategy combined with rounding to 15‑minute boundaries. It demonstrates clean reasoning about time intervals and edge cases like crossing midnight. The modulo variant is equally optimal and often considered a cleaner implementation once you recognize that every valid round aligns to multiples of 15.

Approach 1: Approach 1: Convert Times to Minutes and Calculate

To determine the number of full rounds played, first convert the login and logout times into total minutes from the start of the day. Then, calculate the number of 15-minute intervals (rounds) that fall completely within this range.

If the logout time is earlier than the login time, it means the session spans midnight and we need to account for the hours after midnight until the logout time.

This C program computes the total number of 15-minute chess rounds between loginTime and logoutTime. First, it converts time strings to total minutes. Next, it calculates and returns the number of complete rounds between these minutes, adjusting for midnight transition by adding 96 (the number of rounds in 24 hours) when necessary.

Code

C

C++

Java

Python

C#

JavaScript

Complexity

The time complexity is O(1) because we perform a fixed number of operations, and the space complexity is O(1) since we only use a constant amount of extra space.

Try this approach in the editor →

Approach 2: Approach 2: Utilize Modulo for Round Calculation

In this approach, we make use of modulo operations to determine the start and end of each 15-minute interval and thus calculate the full intervals the session covered in a slightly different method. This calculation is crucial when dealing with transitions over midnight as seen in the problem description.

This C solution converts login and logout times to minutes properly accounting for wrapping using the modulo operator. The rounds are calculated based on division by 15 and adjusted for cross-day dive by adding 96 when necessary.

Code

C

C++

Java

Python

C#

JavaScript

Complexity

The complexity here remains O(1) for time and space as the amount of arithmetic operations does not scale with input size.

Try this approach in the editor →

Approach 3: Convert to Minutes

We can convert the input strings to minutes a and b. If a > b, it means that it crosses midnight, so we need to add one day's minutes 1440 to b.

Then we round a up to the nearest multiple of 15, and round b down to the nearest multiple of 15. Finally, we return the difference between b and a. Note that we should take the larger value between 0 and b - a.

The time complexity is O(1), and the space complexity is O(1).

Code

Python

Java

C++

Go

TypeScript

Try this approach in the editor →

Complexity Comparison

ApproachComplexity
Approach 1: Convert Times to Minutes and Calculate

The time complexity is O(1) because we perform a fixed number of operations, and the space complexity is O(1) since we only use a constant amount of extra space.

Approach 2: Utilize Modulo for Round Calculation

The complexity here remains O(1) for time and space as the amount of arithmetic operations does not scale with input size.

Convert to Minutes

Detailed Complexity Analysis

ApproachTimeSpaceWhen to Use
Convert Times to Minutes and CalculateO(1)O(1)Best general solution. Easy to reason about and handles midnight edge cases clearly.
Modulo-Based Round AlignmentO(1)O(1)When you want concise arithmetic logic using modulo to align times to 15‑minute intervals.

Video Solution

Leetcode Weekly Contest 246 | 1904. The Number of Full Rounds You Have Played in EnglishCompetitive Somya748 views views

Watch 5 more video solutions →

Frequently Asked Questions

Is The Number of Full Rounds You Have Played easy or hard?
The problem is rated Medium because the logic is simple but edge cases can cause mistakes. Handling sessions that cross midnight and correctly rounding to 15‑minute intervals requires careful reasoning. Once times are converted to minutes, the final calculation becomes straightforward.
The Number of Full Rounds You Have Played Python/Java solution
In Python or Java, parse the hour and minute components from the input string, convert them to total minutes, and adjust for overnight sessions if necessary. Align the start and end times to multiples of 15 using arithmetic or modulo operations. Finally divide the interval by 15 to count completed rounds.
How to solve The Number of Full Rounds You Have Played in O(1)?
Convert both timestamps from HH:MM format into total minutes from midnight. If the logout time is smaller than the login time, add 1440 minutes to represent the next day. Round the login time up to the next multiple of 15 and round the logout time down to the previous multiple of 15, then compute (end - start) / 15 to count complete rounds.
What is the best approach for The Number of Full Rounds You Have Played?
The best approach converts login and logout times into total minutes and then aligns them to the nearest 15‑minute boundaries. Round the start time up to the next multiple of 15 and round the end time down to the previous multiple of 15. The number of full rounds equals the difference divided by 15. This solution runs in O(1) time and O(1) space.
Is The Number of Full Rounds You Have Played asked at Google/Amazon/Meta?
Time‑interval and rounding problems similar to this appear in interviews at companies like Amazon and Google. They test your ability to reason about edge cases such as midnight wrap‑around and discrete time buckets. While the exact problem may vary, the same math and string‑parsing concepts frequently appear.
What data structure is used in The Number of Full Rounds You Have Played?
No complex data structure is required. The solution mainly uses integer arithmetic after parsing strings representing time. The problem focuses on math operations, modular arithmetic, and careful handling of time boundaries.
What is the time complexity of The Number of Full Rounds You Have Played?
The time complexity is O(1) because the algorithm performs a fixed number of operations: parsing two strings, doing arithmetic conversions, and computing a difference. No iteration over input size is required. Space complexity is also O(1) since only a few integer variables are used.

Ready to solve this problem?

Practice The Number of Full Rounds You Have Played with our built-in code editor and test cases.

Practice on FleetCode