Calculate Delayed Arrival Time - 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 actually arrive at the station.

Note that the time in this problem is in 24-hours format.

Input & Output

Example 1 — Basic Case
$ Input: arrivalTime = 15, delayedTime = 5
Output: 20
💡 Note: Train was scheduled at 15:00, delayed by 5 hours, so arrives at 20:00
Example 2 — Wraparound Case
$ Input: arrivalTime = 22, delayedTime = 5
Output: 3
💡 Note: 22 + 5 = 27, but 27 % 24 = 3, so train arrives at 03:00 next day
Example 3 — Large Delay
$ Input: arrivalTime = 10, delayedTime = 50
Output: 12
💡 Note: 10 + 50 = 60, and 60 % 24 = 12, so arrives at 12:00 after multiple day cycles

Constraints

  • 1 ≤ arrivalTime ≤ 23
  • 1 ≤ delayedTime ≤ 109

Visualization

Tap to expand
Calculate Delayed Arrival Time - 24 Hour Clock SystemOriginal Time2222:00+Delay55 hours=Sum27Raw sumFinal Time303:0027 % 24 = 3 (24-hour clock wraparound)Train arrives at 03:00 the next day
Understanding the Visualization
1
Input
Original arrival time and delay hours
2
Process
Add delay and handle 24-hour wraparound
3
Output
Final arrival time in 24-hour format
Key Takeaway
🎯 Key Insight: Use modulo arithmetic (% 24) to handle clock wraparound efficiently in constant time
Asked in
Meta 15 Google 12
16.7K Views
Medium Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen