Leetcode 2651: Calculate Delayed Arrival Time

grid47
grid47
Exploring patterns and algorithms
Feb 15, 2024 4 min read

You are given two integers: ‘arrivalTime’, representing the scheduled arrival time of a train in hours (in 24-hour format), and ‘delayedTime’, representing the delay in hours. Your task is to compute the time at which the train will actually arrive at the station, taking into account the delay.
Problem
Approach
Steps
Complexity
Input: The input consists of two integers: 'arrivalTime' (1 <= arrivalTime < 24) and 'delayedTime' (1 <= delayedTime <= 24).
Example: arrivalTime = 9, delayedTime = 4
Constraints:
• 1 <= arrivalTime < 24
• 1 <= delayedTime <= 24
Output: Return the time at which the train will arrive at the station, which can be in 24-hour format.
Example: Output: 13
Constraints:
• The result will be an integer between 0 and 23 (inclusive).
Goal: The goal is to compute the new arrival time after adding the delay to the given arrival time. The result should be returned in 24-hour format.
Steps:
• Step 1: Add the 'delayedTime' to the 'arrivalTime'.
• Step 2: If the sum exceeds 24 hours, subtract 24 to wrap around the time in 24-hour format.
• Step 3: Return the final computed arrival time.
Goal: The solution should handle times correctly in the 24-hour format.
Steps:
• 1 <= arrivalTime < 24
• 1 <= delayedTime <= 24
Assumptions:
• The input values for 'arrivalTime' and 'delayedTime' are valid integers within the given constraints.
• The result is expected in 24-hour format.
Input: Input: arrivalTime = 9, delayedTime = 4
Explanation: The scheduled arrival time is 9:00 hours. Adding a delay of 4 hours gives us 13:00 hours, so the output will be 13.

Input: Input: arrivalTime = 20, delayedTime = 7
Explanation: The scheduled arrival time is 20:00 hours. Adding a delay of 7 hours gives us 27:00, which, when wrapped around in 24-hour format, becomes 3:00 hours. So the output will be 3.

Link to LeetCode Lab


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