Intermediatecoding Verified
Josephus problem: n people stand in a circle and every k-th person is eliminated until one remains. Find the survivor's position.
ReportedSource: GeeksforGeeks interview experience: Apple
Quick answerFree
Iterative recurrence pos = (pos + k) % m for m = 2..n, answer pos + 1. O(n). For k = 2, survivor = 2l + 1 where n = 2^m + l.
Detailed answer· ~100 words
Interview PrepUnlock the full answer with Interview Prep
Get a ~100-word model answer and a runnable reference solution, plus 28 more Algorithms questions.
Also in Pro (₹499 / 90 days).
Reference solution· runs in the browser sandbox
Interview PrepUnlock with Interview Prep
+ 28 more Algorithms questions in Interview Prep, each with the full answer.