Problem Description
Given a train's arrival time and the delay in hours, compute the new arrival time in 24-hour format. If the sum equals 24, the time wraps around to 0 (midnight).
Key Insights
- The problem requires a simple addition of two values: arrivalTime and delayedTime.
- Since time is in 24-hour format, the result must be taken modulo 24.
- Using the modulo operator correctly handles any wrap-around cases (e.g., when the result is 24 or greater).
Space and Time Complexity
Time Complexity: O(1) Space Complexity: O(1)
Solution
The solution is straightforward:
- Add the arrivalTime and delayedTime.
- Use the modulo operator with 24 to adjust the result to the 24-hour format.
- Return the computed time. This approach efficiently uses constant time and space, relying only on basic arithmetic operations.