Josephus Problem
Medium

Problem Statement

There are N people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people K are skipped and the next person is executed. The elimination proceeds around the circle, which is shrinking in size, until only the last person remains. Find the position of the last person.

Examples

1Example 1
Input:
{ "n": 5, "k": 2 }
Output:
3
2Example 2
Input:
{ "n": 7, "k": 3 }
Output:
4
3Example 3
Input:
{ "n": 41, "k": 2 }
Output:
19
Loading...

Sign in to Run Code and Submit