FastPrepFind the Winner of the Circular Game

Find the Winner of the Circular Game

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Players numbered 1 through n stand in a circle. Starting with player 1, count k remaining players including the current player, eliminate that player, and resume with the next remaining player. Return the final survivor.

Function

findTheWinner(n: int, k: int) → int

Examples

Example 1

n = 5k = 2return = 3

The elimination order is 2, 4, 1, 5, leaving 3.

Constraints

  • 1 <= n <= 500.
  • 1 <= k <= 10^9.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int findTheWinner(int n, int k) {
  // Write your code here.
}
n5
k2
expected3
Checking account…