Calculate Delayed Arrival Time — LeetCode 2651 Python Solution

EasyMath
Problem
#2651
Reading time
2 min

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

Python
class Solution:
    def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int:
        return (arrivalTime + delayedTime) % 24

Complexity

MeasureComplexity
TimeO(n) or O(1)
SpaceO(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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview