Imagine n friends sitting in a circle playing an elimination game - this is the famous Josephus Problem! ๐ฏ
The friends are numbered 1 to n clockwise. Starting from friend 1, you count k friends clockwise (including your starting position). The k-th friend gets eliminated and leaves the circle.
Then, you start counting again from the next friend clockwise and repeat the process. This continues until only one winner remains.
Goal: Given n friends and step size k, determine which friend wins the game.
Example: With 5 friends and k=2, starting from friend 1, count 2 positions โ eliminate friend 2, then start from friend 3, count 2 โ eliminate friend 4, and so on.
Input & Output
Constraints
- 1 โค n โค 500
- 1 โค k โค n
- n represents the number of friends in the circle
- k represents the step size for counting