Medium · Linked Lists

Last Man 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=2

Output: survivor 3

Example 2

n=7, k=3

Output: survivor 4

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Linked Lists problems