Calculate Delayed Arrival Time — LeetCode 2651 Python Solution
- Problem
- #2651
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours. Return the time when the train will arrive at the station.
Example
- Input
- arrivalTime = 15, delayedTime = 5
- Output
- 20
- Explanation
- Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).
Python solution
class Solution:
def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int:
return (arrivalTime + delayedTime) % 24Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) or O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 2651. Calculate Delayed Arrival Time is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2651. Calculate Delayed Arrival Time?
- LeetCode 2651. Calculate Delayed Arrival Time is rated Easy on LeetCode.
- What topics does LeetCode 2651. Calculate Delayed Arrival Time cover?
- LeetCode 2651. Calculate Delayed Arrival Time is tagged Math on LeetCode.