- Published on
Google | L3 | Screening Interview
- Author
- Shared Anonymously
Hi everyone,
I recently had a screening round with Google. The question was:
There is an N player tournament.
Players have rank 1 to N and each player has a unique rank. Players with lower
rank wins with player having higher rank. Player with rank 1 wins with every
other player.
The tournament is a knockout tournament. Players that are next to each other on
the input list, play against each other. In the 1st round: the first two players
meet in the first match, the next two players meet in the second match, and so on.
In the 2nd round: in the first match, the winner of the first match of the 1st
round and the winner of the second match of the 1st round will play together.
And similarly, in the second match, the winner of the third match of the 1st
round and the winner of the fourth match of the 1st round will play together.
E.g. if we have 8 players with their ranks [1 2 3 4 5 6 7 8], the tournament looks like this:
1st round matches: [1 2] [3 4] [5 6] [7 8]
2nd round matches: [1 3] [5 7]
3rd round matches: [1 5]
champion : [1]
We are calling a sequence of players (e.g. [1 2 3 4 5 6 7 8]) a matchup.
"Valid matchup" definition:
A matchup is valid when in each round, the best (rank=1) player plays
with the worst player (rank=N), the second best player plays with the second
worst player, and so on.
Write a Python function that given a matchup, finds out whether it is a valid
matchup.
I couldn't understand how I solved it because I didn't understand the task.
I will be glad to hear your comments and solutions.
Thanks for helping :)