n = number of people standing in a circle.
k = number of people to count over each time
Each person is given a unique (incrementing) id. Starting with the first person (the lowest id), they begin counting from 1 to k.
The person at k is then removed and the circle closes up. The next remaining person (following the eliminated person) resumes counting at 1. This process repeats until only one person is left, the winner.
The solution must provide:
the id of each person in the order they are removed from the circle
the id of the winner.
Use as little memory as possible.
Make the solution run as fast as possible.
For Example if n= 5 k = 3
Answer : 3,1,5,2
n = 10 k = 2
Answer 2, 4, 6, 8, 10, 3, 7, 1, 9
PS: Return in an array