FunctionRacerProblemsRace

Two Teams in a Circle

MediumStacks and queuesPython, JavaScript, TypeScript, Java, C++

Players sit in a circle, and seats[i] is R or B, the team of the player in seat i. Turns go around in seat order, from seat 0 to the last seat and then back to seat 0, again and again. On their turn, a player who is still in the game knocks out the first player of the other team found by going around the circle from their seat. Players who are out skip their turns.

The game ends as soon as only one team has players left, which may already be true at the start. Return the seats of the players still in the game, in increasing order.

Example 1

seats "RBB"
returns [2]

Seat 0 knocks out seat 1, then seat 2 knocks out seat 0.

Example 2

seats "RRBBB"
returns [1]

Seats 0 and 1 knock out seats 2 and 3, seat 4 knocks out seat 0, and on the next lap seat 1 knocks out seat 4.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems