loading...

re: Daily Challenge #62 - Josephus Survivor VIEW POST

FULL DISCUSSION
 

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()
Code of Conduct Report abuse