An Easy Problem
Practice
4.1 (16 votes)
Algorithms
Easy
Greedy algorithms
Problem
90% Success 3573 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Mr X loves his clock. His clock displays time in the $$ HH:MM $$ Format using the 24 hour system, the first 2 characters in the string are used to display the current hour, with possible leading zeros. Also, the last 2 characters are used to display the current minutes, also with possible leading zeroes.

Now, Mr X came up with a new thing, where he calls a particular time displayed by the clock good if the sum of all digits written on the clock during that time is divisible by a given number $$x$$.

You have been given the current time displayed by the clock and an integer $$ x $$. You need to find the minimum number of minutes Mr X needs to wait, to see a good time being displayed by the clock. If the clock is already displaying a good time, Mr X does not need to wait at all.

If the clock will never ever display a good time, then print $$ -1 $$ instead as the answer.

Input Format:

The first line contains a string in the $$HH:MM$$ format. The next line contains a single integer $$x$$.

Output Format:

Print a single integer denoting the minimum number of minutes Mr X needs to wait to see a good time being displayed by the clock, or $$ -1 $$ if this can never happen.

Constraints :

$$ 0 \le HH < 24 $$

$$ 0 \le MM < 60 $$

$$ 1 \le x < 20 $$

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
27 votes
Tags:
ReadyBasic ProgrammingHard
Points:20
5 votes
Tags:
Greedy AlgorithmsAlgorithmsBasics of Greedy AlgorithmsImplementationHashmap
Points:20
8 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsImplementationString Manipulation