SDE
Interview Date
2026-07-28
Result
Rejected
Difficulty
Medium
Rounds
02
Drive Type
On-Campus
Topics asked
Detailed experience
There are N participants, each having a unique rank from 1 to N. Their current order is represented by an array A, where A[i] denotes the rank of the participant at position i. A round is considered valid if every consecutive pair of participants satisfies the following condition: The participants at positions (0,1), (2,3), (4,5), ... are compared. For every pair, one participant must have the smallest remaining rank x and the other must have the largest remaining rank M - x + 1, where M is the largest rank still in contention for that round. In other words, the valid pairs are: (1, M) (2, M-1) (3, M-2) and so on, in either order within the pair. After each valid round, the participant with the better rank (smaller rank value) advances to the next round, preserving the left-to-right order of advancing participants. The tournament continues until only one participant remains. Determine whether the given arrangement can successfully complete all rounds. Return True if every round is valid; otherwise, return False.