Given two times in string “HH:MM” format. Here ‘H’ shows hours and ‘M’ shows minutes. You have to find the difference in the 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of all numbers formed having 4 atmost X times, 5 atmost Y times and 6 atmost Z times
- Times required by Simple interest for the Principal to become Y times itself
- Check if the given array can be reduced to zeros with the given operation performed given number of times
- Queries to increment array elements in a given range by a given value for a given number of times
- Check if given array can be made 0 with given operations performed any number of times
- GCD of two numbers formed by n repeating x and y times
- Count how many times the given digital clock shows identical digits
- Check if X and Y can be made zero by using given operation any number of times
- Count of subarrays which contains a given number exactly K times
- Maximum inversions in a sequence of 1 to N after performing given operations at most K times
- Minimum difference between any two primes from the given range
- Maximum profit by buying and selling a share at most k times
- Number of times the largest perfect square number can be subtracted from N
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Maximum score after flipping a Binary Matrix atmost K times
- Find the number of times every day occurs in a month
- Find the value of N XOR'ed to itself K times
- Compute power of power k times % m
- Maximum number of dots after throwing a dice N times
- Probability of getting a sum on throwing 2 Dices N times
Improved By : ApurvaRaj