Medium · Linked Lists
Last men standing
Given n people standing in a circle, numbered 1 to n, and an integer k, start counting at person 1, remove the person counted k, and continue counting from the next person, repeating until one person remains; return that person's number.
Examples
Example 1
n=5, k=2Output: survivor 3
Example 2
n=7, k=3Output: survivor 4
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.