FastPrepJosephus Elimination Until Half Remain

Josephus Elimination Until Half Remain

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

People labeled 1 through n stand clockwise. The current person initially is 1. Advance k positions clockwise, not counting the current person; remove the person landed on. Resume from the next survivor.

Return removals in order, stopping when ceil(n/2) people remain.

Function

eliminateUntilHalf(n: int, k: int) → int[]

Examples

Example 1

n = 6k = 4return = [5,4,6]

Exclusive counting from 1 lands on 5; continue until three survivors remain.

Constraints

  • 1 <= n <= 10^4.
  • 0 <= k <= 10^9.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] eliminateUntilHalf(int n, int k) {
  // Write your code here.
}
n6
k4
expected[5,4,6]
Checking account…