Algorithm to solve ClockRotationProblem