Google Mock Interview | L4
Anonymous User
2022

N Rank player tournament
Each player has a unique rank

sequence - [1 2 3 4 5 6 7 8]

1st round: [1 2] [3 4] [5 6] [7 8]
2nd round: [1 3] [5 7]
3rd round: [1 5]
champion : [1]

Output = invalid/false
draw - 1st best player plays with 1st worst player, valid for all matches in all rounds
tell if given sequence is valid draw

I gave solution to just check pairs in sequence. Problem statement seems vague to me.

boolean checkValidDraw(int[] seq, List<List<Integer>> rounds, int n) {
    int rankSum = n+1;
    
    for(int i=0; i<n-1; i+=2) {
        if(seq[i]+seq[i+1]!=rankSum) {
            return false;
        }
    }

    return true;
}

TC - O(N/2)
SC - O(1)

Comments (12)