#1904
Medium Algorithms The number of full rounds you have played
Math String
43.5% acceptance
Feb 25, 2026
230
265
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.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn number_of_rounds(login_time: String, logout_time: String) -> i32 {
let parse = |s: &str| -> i32 {
let h: i32 = s[..2].parse().unwrap();
let m: i32 = s[3..].parse().unwrap();
h * 60 + m
};
let mut start = parse(&login_time);
let mut end = parse(&logout_time);
if end < start {
end += 24 * 60;
}
// Round start up to next multiple of 15
start = (start + 14) / 15 * 15;
// Round end down to previous multiple of 15
end = end / 15 * 15;
(end - start).max(0) / 15
}
}