Medium · Linked Lists
Last men standing
Given n ≥ 1 people standing in a circle, numbered 1 to n, and an integer k ≥ 1, 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
Open every published interview problem, solution, scene, and memory room free, with no account.