#1823

Find the Winner of the Circular Game

pupil · 415 · lc medium +25 · verified · 82.2% accepted · 4,091 likes · top 94%

Description

There are n friends in a clockwise circle numbered 1 to n. Starting at friend 1, count k friends clockwise; the kth friend is eliminated. Repeat from the next friend until one remains. Return the winning friend's number.

Code

1
2
3