2651. Calculate Delayed Arrival Time LeetCode Solution

In this guide, you will get 2651. Calculate Delayed Arrival Time LeetCode Solution with the best time and space complexity. The solution to Calculate Delayed Arrival Time problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Calculate Delayed Arrival Time solution in C++
  4. Calculate Delayed Arrival Time solution in Java
  5. Calculate Delayed Arrival Time solution in Python
  6. Additional Resources
2651. Calculate Delayed Arrival Time LeetCode Solution image

Problem Statement of Calculate Delayed Arrival Time

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.
Note that the time in this problem is in 24-hours format.

Example 1:

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).

Example 2:

Input: arrivalTime = 13, delayedTime = 11
Output: 0
Explanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).

Constraints:

1 <= arrivaltime < 24
1 <= delayedTime <= 24

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

2651. Calculate Delayed Arrival Time LeetCode Solution in C++

class Solution {
 public:
  int findDelayedArrivalTime(int arrivalTime, int delayedTime) {
    return (arrivalTime + delayedTime) % 24;
  }
};
/* code provided by PROGIEZ */

2651. Calculate Delayed Arrival Time LeetCode Solution in Java

class Solution {
  public int findDelayedArrivalTime(int arrivalTime, int delayedTime) {
    return (arrivalTime + delayedTime) % 24;
  }
}
// code provided by PROGIEZ

2651. Calculate Delayed Arrival Time LeetCode Solution in Python

class Solution:
  def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int:
    return (arrivalTime + delayedTime) % 24
# code by PROGIEZ

Additional Resources

See also  594. Longest Harmonious Subsequence LeetCode Solution

Happy Coding! Keep following PROGIEZ for more updates and solutions.