PingPongQueue
TCO17 Round 1A · 2017-03-31 · by Nickolas
Problem Statement
You are given a
All people in the group would like to play but they only have a single table. Therefore, only two people can play at any given time.
There will be a sequence of games, numbered starting from 1. Game 1 will be played by the players who correspond to skills[0] and skills[1]. All the remaining people will form a queue, in the order in which they are given in skills. After each game the following things will happen, in order:
- The person who lost the game leaves the table and goes to the end of the queue.
- If the person who won the game has already won N games in a row, they also leave the table and they go to the end of the queue (behind the person who lost the last game).
- While there are fewer than two people at the table, the first person in the queue leaves the queue and goes to the table.
- The two people at the table play the next game.
Constraints
- skills will contain between 2 and 50 elements, inclusive.
- Each element of skills will be between 1 and 50, inclusive.
- All elements of skills will be distinct.
- N will be between 1 and 100, inclusive.
- K will be between 1 and 1000, inclusive.
{1, 2, 3}
2
2
Returns: {2, 3 }
In all annotations, we call people by their skill. For example, "player 7" means "the player whose skill level is 7". In this example players 1 and 2 play the first game, and player 2 wins. For the second game, player 3 joins player 2, so we return { 2, 3 }.
{1, 2, 3}
2
4
Returns: {1, 2 }
The sequence of games is as follows: Player 1 loses to player 2. Player 2 loses to player 3. Player 1 loses to player 3. After this player 1 joins the queue, player 3 also steps down because he just won 2 games in a row and joins the queue. Player 1 loses to player 2.
{50, 1}
1
1
Returns: {1, 50 }
{8, 12}
1
1000
Returns: {8, 12 }
{31, 29}
100
1
Returns: {29, 31 }
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PingPongQueue with a public method vector<int> whoPlaysNext(vector<int> skills, int N, int K) · 70 test cases · 2 s / 256 MB per case