← Back to challenges

Simplified Josephus

JavaScriptHardalgebramath

Instructions

Given n people, find the survivor. Starting from the first person, they kill the person to their left and the next surviving person kills the person to their left. This keeps happening until 1 person survives. Return that person's number.

Examples

josephus(1) ➞ 1

josephus(8) ➞ 1

josephus(41) ➞ 19

Notes

You can search up the problem if you are too confused about the instructions.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.