Leetcode 1904: The Number of Full Rounds You Have Played

grid47
grid47
Exploring patterns and algorithms
Apr 30, 2024 6 min read

You are participating in an online chess tournament where rounds start every 15 minutes, starting at 00:00. You are given two times: loginTime and logoutTime. Your task is to calculate the number of full rounds you have participated in during the period from loginTime to logoutTime.
Problem
Approach
Steps
Complexity
Input: Two strings: `loginTime` and `logoutTime` representing the times when you log in and log out respectively.
Example: loginTime = "08:25", logoutTime = "09:05"
Constraints:
• loginTime and logoutTime are in the format hh:mm.
• 00 <= hh <= 23
• 00 <= mm <= 59
• loginTime and logoutTime are not equal.
Output: Return the number of full chess rounds you have participated in during the given time window.
Example: 1
Constraints:
• The result is an integer representing the count of full rounds played.
Goal: Calculate the number of full chess rounds you have played between `loginTime` and `logoutTime`.
Steps:
• Convert `loginTime` and `logoutTime` to minutes from 00:00.
• If `logoutTime` is earlier than `loginTime`, split the time into two parts: from `loginTime` to midnight, and from midnight to `logoutTime`.
• Count the full rounds (each lasting 15 minutes) in both parts of the time window.
Goal: The input times are valid and meet the specified constraints.
Steps:
• loginTime and logoutTime are valid time strings in hh:mm format.
• 1 <= loginTime.length, logoutTime.length <= 5
Assumptions:
• The input times are in the 24-hour format with no leading zeros in the time parts.
Input: Input: loginTime = "22:50", logoutTime = "01:30"
Explanation: You played 1 full round from 22:50 to 23:00, and 5 full rounds from 00:00 to 01:30. Total = 6 full rounds.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus