r/csinterviewproblems • • Dec 18 '15
You have 2 analog clocks, both start at the same time of day, one spins clockwise the other anticlockwise, how many times will the backwards clocks time match the normal clocks time?
6
Upvotes
3
u/[deleted] Dec 18 '15
You can intuitively figure out this is 4 times by just thinking about it, but i decided to use a solution that relies on rotating arrays.
You fill 2 array with 12->11 like a clock and one you rotate left to right and the other you rotate right to left. I'm not sure how efficient it is, but its extremely easy to understand and will never have overflow problems.
Here is an example in C++:
0
u/[deleted] Dec 18 '15
[deleted] — view deleted comment