You are not logged in. Please login at to post your questions!


CLOCK - Editorial


Contest Link

Author: Tushar Kadam

Tester: Sangram Desai

Editorialist: Tushar Kadam





Given time in HH MM SS format and you have to find what will be time after hour hand moves by x degrees.


If hour hand moves by 1 degree then 2 minutes will happen in 12 hour clock. As x is integer and smallest change in x can be only 1 degree hence second hand will come to its original position whatever may be the value of x i.e SS field will not change. Now find if minutes to add in MM field is greater than 60 or not . If final MM field > 60 then add extra minutes in hour by converting minutes to hour.

Note : if x > 360 that means hour hand has moved by more than 360 degrees i.e several complete rotations have happened. so to solve one can do x = x%360 which will have same effect.

Possible testcases where you may get wrong answers:

input :


11 58 59 1

11 59 1 1

12 58 55 28

11 2 23 29

11 2 0 361

11 59 27 62


12 0 59

12 1 1

1 54 55

12 0 23

11 4 0

2 3 27


Author's solution Java Solution

Tester's solution Python Solution.

This question is marked "community wiki".

asked 09 Sep, 14:22

cis_pie's gravatar image

accept rate: 10%

edited 14 Sep, 18:07

admin's gravatar image

0★admin ♦♦

The preliminary step here is to find out what $1$ degree motion of the hour hand means in terms of time. 0ne full rotation of the hour hand is $12$ hours or $12\times 60 = 720$ minutes, and conveniently we have $720/360 = 2$ exactly; giving $2$ minutes per degree.

If, instead of degrees, the question had asked the time after the hour hand is moved by $x$ gradians, which have $400$ for a full turn, we would have had to go down to an effect in seconds, with $720\times 60 = 43200$ second in a full turn of the hour hand and thus $108$ seconds per gradian.


answered 13 Sep, 02:43

joffan's gravatar image

accept rate: 11%

@joffan Thanks for your suggestion about use of gradians in problem . But I wanted to design an easy problem So I deliberately made a special case in which that it turns out that 1 degree corresponds to 2 minutes.

So bonus question : x can be negative

(13 Sep, 23:43) cis_pie5★

Oh sure, I wasn't complaining at all about the use of degrees. Just pointing out where the 1 degree = 2 minutes comes from.

And my alternative example was gradians not radians - they would be much more difficult since a full turn in radians is $2\pi$.

PS: re bonus question: my code already worked correctly. :-)

(13 Sep, 23:51) joffan4★

Oh my bad! Edited! And I just saw your code.

(14 Sep, 00:09) cis_pie5★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 09 Sep, 14:22

question was seen: 412 times

last updated: 14 Sep, 18:07