Given a generic digital clock, having h number of hours and m number of minutes, the task is to find how many times the clock shows identical time. A specific time is said to be identical if every digit in the hours and minutes is same i.e. the time is of type D:D, D:DD, DD:D or DD:DD.
Note that the time is written on the digital clock without any leading zeros and the clock shows time between 0 to h – 1 hours and 0 to m – 1 minutes. Few examples of identical times are:
Input: hours = 24, minutes = 60
The clock has 24 hours and 60 minutes.
So the identical times will be:
Single digit hours and single digit minutes -> 0:0, 1:1, 2:2, …., 9:9
Single digit hours and double digit minutes -> 1:11, 2:22, 3:33, 4:44 and 5:55
Double digit hours and single digit minutes -> 11:1 and 22:2
Double digit hours and double digit minutes -> 11:11, 22:22
Total = 10 + 5 + 2 + 2 = 19
Input: hours = 34, minutes = 50
Approach: As we can see in the explained example, we have to first count the single digit (of hours) identical times and then double-digit hours. During each of these counts, we need to consider single digit minutes as well as double-digit minutes.
There will be two loops. First loop deals with single digit hours. And the second deals with double digit hours. In each of the loops, there should be two conditions. First, if iterator variable is less than total minutes, then increment the counter. Second, if (iterator variable + iterator variable * 10) is less than total minutes, increment the counter. At the end, we will have the total identical times that clock shows.
Below is the implementation of the above approach:
- C program to print digital clock with current time
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Convert time from 24 hour clock to 12 hour clock format
- Count of subarrays which contains a given number exactly K times
- Count distinct substrings that contain some characters at most k times
- Count of numbers appearing in the given ranges at-least K times
- Count of Numbers in a Range where digit d occurs exactly K times
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count of Binary strings of length N having atmost M consecutive 1s or 0s alternatively exactly K times
- Count even and odd digits in an Integer
- Build a DFA to accept a binary string containing "01" i times and "1" 2j times
- Count of numbers with all digits same in a given range
- Count numbers less than N containing digits from the given set : Digit DP
- Count of integers of length N and value less than K such that they contain digits only from the given set
- Count of numbers from range [L, R] that end with any of the given digits
- Given count of digits 1, 2, 3, 4, find the maximum sum possible
- C program to Count the digits of a number
- Count of Octal numbers upto N digits
- Count of Numbers in Range where the number does not contain more than K non zero digits
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.