Given the initial clock time h1:m1 and the present clock time h2:m2, denoting hour and minutes in 24-hours clock format. The present clock time h2:m2 may or may not be correct. Also given a variable K which denotes the number of hours passed. The task is to calculate the delay in seconds i.e. time difference between expected time and given time.
Input: h1 = 10, m1 = 12, h2 = 10, m2 = 17, k = 2
Output: 115 minutes
The clock initially displays 10:12. After 2 hours it must show 12:12. But at this point, the clock displays 10:17. Hence, the clock must be lagging by 115 minutes. so the answer is 115.
Input: h1 = 12, m1 = 00, h2 = 12, m2 = 58, k = 1
Output: 2 minutes
The clock initially displays 12:00. After 1 hour it must show 13:00. But at this point, the clock displays 12:58. Hence, the clock must be lagging by 2 minutes. so the answer is 2.
- Convert given time in h:m format to number of minutes. It is simply 60*h+m.
- Calculate both the computed time(adding K hours to the initial time).
- Find the difference in minutes which will be the answer.
Below is the implementation of the above approach.
Lag = 2 minutes
Time Complexity: O(1)
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Program to find the time after K minutes from given time
- Add given n time durations
- Time taken per hour for stoppage of Car
- Convert given time into words
- Calculate speed, distance and time
- Print system time in C++ (3 different ways)
- Java | Current date and time
- Time Functions in Python | Set-2 (Date Manipulations)
- Convert timestamp to readable date/time in PHP
- C++ Program to print current Day, Date and Time
- Minimum time required to fill a cistern using N pipes
- Minimum time required to complete a work by N persons together
- Find time when hour and minute hands superimpose
- C program to print digital clock with current time
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.