2651. Calculate Delayed Arrival Time

Math

Explanation:

To calculate the delayed arrival time, we simply add the arrival time to the delayed time. If the sum exceeds 24 hours, we need to convert it to the 24-hour format (0-23 hours).

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

:

class Solution {
    public int calculateDelayedArrivalTime(int arrivalTime, int delayedTime) {
        int totalHours = (arrivalTime + delayedTime) % 24;
        return totalHours;
    }
}

Code Editor (Testing phase)

Improve Your Solution

Use the editor below to refine the provided solution. Select a programming language and try the following:

  • Add import statement if required.
  • Optimize the code for better time or space complexity.
  • Add test cases to validate edge cases and common scenarios.
  • Handle error conditions or invalid inputs gracefully.
  • Experiment with alternative approaches to deepen your understanding.

Click "Run Code" to execute your solution and view the output. If errors occur, check the line numbers and debug accordingly. Resize the editor by dragging its bottom edge.