tell me the best way to find the difference between two values in a cyclic system?

Assuming input already in range 1-12, you might do

return b - a + (b < a) * 12;

benchmark showing a 2 times performance gain over cigien’s solution.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top