Given two times in string “HH:MM” format. Here ‘H’ shows hours and ‘M’ shows minutes. You have to find the difference in same string format between these two strings. But both given strings should follow these cases.
1) Time 1 will be less than or equal to time2
2) Hours will be possible from 0 to 23.
3) Minutes will be possible from 0 to 59
Input : s1 = "14:00"; s2 = "16:45"; Output : result = "2:45" Input : s1 = "1:04" s2 = "13:05" Output : result = "12:01"
The idea is to first remove colon. After removing colon, hour difference can be computed using simple mathematics.
This article is contributed by Harshit Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Times required by Simple interest for the Principal to become Y times itself
- GCD of two numbers formed by n repeating x and y times
- Probability of getting a sum on throwing 2 Dices N times
- Find the value of XXXX.....(N times) % M where N is large
- Find the number of times every day occurs in a month
- Count different numbers possible using all the digits their frequency times
- Convert a number of length N such that it contains any one digit at least 'K' times
- Maximum number of dots after throwing a dice N times
- Count of Numbers in a Range where digit d occurs exactly K times
- Find the K-th minimum element from an array concatenated M times
- Smallest integer greater than n such that it consists of digit m exactly k times
- Maximum profit by buying and selling a share at most k times
- Maximum score after flipping a Binary Matrix atmost K times
- Count how many times the given digital clock shows identical digits
- Queries to check whether all the elements can be made positive by flipping signs exactly K times