Josephus Survivor
People labeled 1 through n stand clockwise. Count from label 1, including it as count one; remove the step-th person, then resume at their next surviving…
People labeled 1 through n stand clockwise. Count from label 1, including it as count one; remove the step-th person, then resume at their next surviving neighbor as count one. Repeat until one remains. Return that original one-based label, not a zero-based coordinate or removal log. Implement josephus_survivor(n, step) in Python or josephusSurvivor(n, step) in other languages, with two scalar arguments.
- 1 <= n <= 2000. - 1 <= step <= 2147483647. - Both arguments are strict integers, not Booleans or fractions. - Return one original label in [1,n]. Zero/negative values are excluded, not clamped. - Coding preserves full n and step bounds; complete teaching circles contain at most 12 people, without limiting the valid int32 step.
Example 1: input n = 5, step = 2; output 3. Remove 2,4,1,5 and keep original label 3.
Example 2: input n = 5, step = 2147483647; output 4. Modulo current size gives removal order 2,5,1,3, leaving 4.
Example 3: input n = 1, step = 9; output 1. A singleton is already the survivor.
Category: Queues. Topic: queue. Difficulty: Medium. Patterns: linear-scan.