Talentd
FleetCode
Make and follow sheets.Sign in

The Number of Full Rounds You Have Played solution and explanation

MediumMathString6 min read43.9% acceptanceUpdated 9 Apr 2026
Leetcode Weekly Contest 246 | 1904. The Number of Full Rounds You Have Played in EnglishCompetitive Somya · 5:02 · 748 viewsWatch on YouTube
5 more videos on this problem
  1. Leetcode Weekly Contest 246 | 1904. The Number of Full Rounds You Have Played in EnglishCompetitive Somya · 5:02 · 748 views
  2. 1904. The Number of Full Rounds You Have Played (Leetcode Medium)Programming Live with Larry · 4:38 · 679 views
  3. Leetcode Weekly Contest 246 | PROBLEM 1903 , 1904 , 1905 | LEETCODE SOLUTION | CODE EXPLAINERcode Explainer · 18:38 · 445 views
  4. 【每日一题】1904. The Number of Full Rounds You Have Played, 6/22/2021Huifeng Guan · 9:43 · 261 views
  5. LeetCode Weekly Contest 246 Question 2: The Number of Full Rounds You Have PlayedCoding Ninjas Webinars and Contest Editorials · 17:34 · 196 views
  6. The Number of Full Rounds You Have Played | Weekly Contest 246 | LeetCode |Algorithm Unlock && Data Structure Deadheads · 7:28 · 114 views

The 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.

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.

def time_to_minutes(time):
    hours, minutes = map(int, time.split(':'))
    return hours * 60 + minutes

def number_of_rounds(login_time, logout_time):
    login_minutes = time_to_minutes(login_time)
    logout_minutes = time_to_minutes(logout_time)
    start_round = (login_minutes + 14) // 15
    end_round = logout_minutes // 15
    if logout_minutes < login_minutes:
        end_round += 96
    return end_round - start_round

print(number_of_rounds("09:31", "10:14"))  # Output: 1
print(number_of_rounds("21:30", "03:00"))  # Output: 22
public class ChessRounds {
    public static int timeToMinutes(String time) {
        int hours = Integer.parseInt(time.substring(0, 2));
        int minutes = Integer.parseInt(time.substring(3, 5));
        return hours * 60 + minutes;
    }

    public static int numberOfRounds(String loginTime, String logoutTime) {
        int loginMinutes = timeToMinutes(loginTime);
        int logoutMinutes = timeToMinutes(logoutTime);
        int startRound = (loginMinutes + 14) / 15;
        int endRound = logoutMinutes / 15;
        if (logoutMinutes < loginMinutes) endRound += 96;
        return endRound - startRound;
    }

    public static void main(String[] args) {
        System.out.println(numberOfRounds("09:31", "10:14")); // Output: 1
        System.out.println(numberOfRounds("21:30", "03:00")); // Output: 22
    }
}
#include <iostream>
#include <string>

int timeToMinutes(const std::string& time) {
    int hours = stoi(time.substr(0, 2));
    int minutes = stoi(time.substr(3, 2));
    return hours * 60 + minutes;
}

int numberOfRounds(const std::string& loginTime, const std::string& logoutTime) {
    int loginMinutes = timeToMinutes(loginTime);
    int logoutMinutes = timeToMinutes(logoutTime);
    int startRound = (loginMinutes + 14) / 15;
    int endRound = logoutMinutes / 15;
    if (logoutMinutes < loginMinutes) endRound += 96;
    return endRound - startRound;
}

int main() {
    std::cout << numberOfRounds("09:31", "10:14") << std::endl; // Output: 1
    std::cout << numberOfRounds("21:30", "03:00") << std::endl; // Output: 22
    return 0;
}
function timeToMinutes(time) {
    const [hours, minutes] = time.split(':').map(Number);
    return hours * 60 + minutes;
}

function numberOfRounds(loginTime, logoutTime) {
    const loginMinutes = timeToMinutes(loginTime);
    const logoutMinutes = timeToMinutes(logoutTime);
    const startRound = Math.ceil(loginMinutes / 15);
    const endRound = Math.floor(logoutMinutes / 15);
    if (logoutMinutes < loginMinutes) endRound += 96;
    return endRound - startRound;
}

console.log(numberOfRounds("09:31", "10:14")); // Output: 1
console.log(numberOfRounds("21:30", "03:00")); // Output: 22;
#include <stdio.h>
#include <stdlib.h>

int calculateRounds(int loginMinutes, int logoutMinutes) {
    int startRound = (loginMinutes + 14) / 15;
    int endRound = logoutMinutes / 15;
    return (endRound - startRound + (logoutMinutes < loginMinutes ? 96 : 0));
}

int timeToMinutes(const char* time) {
    int hours = (time[0] - '0') * 10 + (time[1] - '0');
    int minutes = (time[3] - '0') * 10 + (time[4] - '0');
    return hours * 60 + minutes;
}

int numberOfRounds(const char* loginTime, const char* logoutTime) {
    int loginMinutes = timeToMinutes(loginTime);
    int logoutMinutes = timeToMinutes(logoutTime);
    return calculateRounds(loginMinutes, logoutMinutes);
}

int main() {
    printf("%d\n", numberOfRounds("09:31", "10:14")); // Output: 1
    printf("%d\n", numberOfRounds("21:30", "03:00")); // Output: 22
    return 0;
}
using System;

public class ChessRounds {
    public static int TimeToMinutes(string time) {
        int hours = int.Parse(time.Substring(0, 2));
        int minutes = int.Parse(time.Substring(3, 2));
        return hours * 60 + minutes;
    }

    public static int NumberOfRounds(string loginTime, string logoutTime) {
        int loginMinutes = TimeToMinutes(loginTime);
        int logoutMinutes = TimeToMinutes(logoutTime);
        int startRound = (loginMinutes + 14) / 15;
        int endRound = logoutMinutes / 15;
        if (logoutMinutes < loginMinutes) endRound += 96;
        return endRound - startRound;
    }

    public static void Main(string[] args) {
        Console.WriteLine(NumberOfRounds("09:31", "10:14")); // Output: 1
        Console.WriteLine(NumberOfRounds("21:30", "03:00")); // Output: 22
    }
}

The Python implementation uses split and map functions to convert time strings to minutes. It calculates the number of board rounds by finding the intervals covered between these minutes, handling the condition where logoutMinutes is smaller than loginMinutes by adding offset rounds.

Complexity

The time complexity is O(1), and space complexity is O(1) due to constant operations and space usage.

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.

def time_to_minutes(time):
    hours, minutes = [int(unit) for unit in time.split(':')]
    return (hours % 24) * 60 + minutes

def number_of_rounds(login_time, logout_time):
    login_minutes = time_to_minutes(login_time)
    logout_minutes = time_to_minutes(logout_time)
    start_round = (login_minutes + 14) // 15
    end_round = logout_minutes // 15
    if logout_minutes < login_minutes:
        end_round += 96
    return end_round - start_round

print(number_of_rounds("09:31", "10:14"))  # Output: 1
print(number_of_rounds("21:30", "03:00"))  # Output: 22
public class ChessRounds {
    public static int timeToMinutes(String time) {
        int hours = Integer.parseInt(time.substring(0, 2)) % 24;
        int minutes = Integer.parseInt(time.substring(3, 5));
        return (hours * 60 + minutes) % 1440;
    }

    public static int numberOfRounds(String loginTime, String logoutTime) {
        int loginMinutes = timeToMinutes(loginTime);
        int logoutMinutes = timeToMinutes(logoutTime);
        int startRound = (loginMinutes + 14) / 15;
        int endRound = logoutMinutes / 15;
        if (logoutMinutes < loginMinutes) endRound += 96;
        return endRound - startRound;
    }

    public static void main(String[] args) {
        System.out.println(numberOfRounds("09:31", "10:14")); // Output: 1
        System.out.println(numberOfRounds("21:30", "03:00")); // Output: 22
    }
}
#include <iostream>
#include <string>

int timeToMinutes(const std::string& time) {
    int hours = stoi(time.substr(0, 2)) % 24;
    int minutes = stoi(time.substr(3, 2));
    return (hours * 60 + minutes) % 1440;
}

int numberOfRounds(const std::string& loginTime, const std::string& logoutTime) {
    int loginMinutes = timeToMinutes(loginTime);
    int logoutMinutes = timeToMinutes(logoutTime);
    int startRound = (loginMinutes + 14) / 15;
    int endRound = logoutMinutes / 15;
    if (logoutMinutes < loginMinutes) endRound += 96;
    return endRound - startRound;
}

int main() {
    std::cout << numberOfRounds("09:31", "10:14") << std::endl; // Output: 1
    std::cout << numberOfRounds("21:30", "03:00") << std::endl; // Output: 22
    return 0;
}
function timeToMinutes(time) {
    const [hours, minutes] = time.split(':').map(Number);
    return (hours * 60 + minutes) % 1440;
}

function numberOfRounds(loginTime, logoutTime) {
    const loginMinutes = timeToMinutes(loginTime);
    const logoutMinutes = timeToMinutes(logoutTime);
    const startRound = Math.ceil(loginMinutes / 15);
    const endRound = Math.floor(logoutMinutes / 15);
    if (logoutMinutes < loginMinutes) endRound += 96;
    return endRound - startRound;
}

console.log(numberOfRounds("09:31", "10:14")); // Output: 1
console.log(numberOfRounds("21:30", "03:00")); // Output: 22;
#include <stdio.h>
#include <stdlib.h>

int timeToMinutes(const char* time) {
    int hours = ((time[0] - '0') * 10 + (time[1] - '0')) % 24;
    int minutes = (time[3] - '0') * 10 + (time[4] - '0');
    return (hours * 60 + minutes) % 1440;
}

int numberOfRounds(const char* loginTime, const char* logoutTime) {
    int loginMinutes = timeToMinutes(loginTime);
    int logoutMinutes = timeToMinutes(logoutTime);
    int start = (loginMinutes + 14) / 15;
    int end = logoutMinutes / 15;
    return end - start + (logoutMinutes < loginMinutes ? 96 : 0);
}

int main() {
    printf("%d\n", numberOfRounds("09:31", "10:14")); // Output: 1
    printf("%d\n", numberOfRounds("21:30", "03:00")); // Output: 22
    return 0;
}
using System;

public class ChessRounds {
    public static int TimeToMinutes(string time) {
        int hours = int.Parse(time.Substring(0, 2)) % 24;
        int minutes = int.Parse(time.Substring(3, 2));
        return (hours * 60 + minutes) % 1440;
    }

    public static int NumberOfRounds(string loginTime, string logoutTime) {
        int loginMinutes = TimeToMinutes(loginTime);
        int logoutMinutes = TimeToMinutes(logoutTime);
        int startRound = (loginMinutes + 14) / 15;
        int endRound = logoutMinutes / 15;
        if (logoutMinutes < loginMinutes) endRound += 96;
        return endRound - startRound;
    }

    public static void Main(string[] args) {
        Console.WriteLine(NumberOfRounds("09:31", "10:14")); // Output: 1
        Console.WriteLine(NumberOfRounds("21:30", "03:00")); // Output: 22
    }
}

The Python solution takes modulo operations for clock wraparound and efficiently handles 15-minute intervals counting, maintaining correctness across timing cycles.

Complexity

The function keeps O(1) complexity on both fronts—space and time—based on direct numerical manipulation.

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).

function numberOfRounds(startTime: string, finishTime: string): number {
    const f = (s: string): number => {
        const [h, m] = s.split(':').map(Number);
        return h * 60 + m;
    };
    let [a, b] = [f(startTime), f(finishTime)];
    if (a > b) {
        b += 1440;
    }
    return Math.max(0, Math.floor(b / 15) - Math.ceil(a / 15));
}
func numberOfRounds(loginTime string, logoutTime string) int {
	f := func(s string) int {
		var h, m int
		fmt.Sscanf(s, "%d:%d", &h, &m)
		return h*60 + m
	}
	a, b := f(loginTime), f(logoutTime)
	if a > b {
		b += 1440
	}
	return max(0, b/15-(a+14)/15)
}
Try this approach in the editor

Complexity comparison

ApproachComplexity
Approach 1: Convert Times to Minutes and Calculate

The time complexity is O(1), and space complexity is O(1) due to constant operations and space usage.

Approach 2: Utilize Modulo for Round Calculation

The function keeps O(1) complexity on both fronts—space and time—based on direct numerical manipulation.

Convert to Minutes–

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.

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.

Comments

Now write it yourselfClose this page and solve The Number of Full Rounds You Have Played in the editor, without looking.
Practise The Number of Full Rounds You Have Played