DEV Community

Discussion on: Daily Challenge #62 - Josephus Survivor

Collapse
 
colorfusion profile image
Melvin Yeo

In Python, not the best answer though, with a complexity of O(n)

def josephus_survivor(n, k):
    arr = list(range(1, n+1))
    idx = 0
    step = k - 1

    while len(arr) > 1:
        idx = (idx + step) % len(arr)
        arr.pop(idx)

    return arr.pop()