CJCoding With Joseph
15free / daySign inCreate account

Josephus Elimination Order

n people numbered 1 to n stand in a circle. Counting from person 1, every k-th person is removed, and counting continues from the next person still in the circle, until everyone has been removed.

Write a function vector<int> eliminationOrder(int n, int k) that simulates this with a queue<int> and returns all n numbers in the order they are removed. You may assume n >= 1 and k >= 1.

The tests print the returned vector separated by spaces. For n = 7, k = 3 the output is exactly what is shown in Expected Output.

For n = 5, k = 2 the output is:
2 4 1 5 3

Do NOT write a main function.

Expected Output:

3 6 2 7 5 1 4
2 4 1 5 3

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.