Last Round for Each Player
Updated
Problem statement
There are N players, numbered from 0 to N - 1, participating in a tournament. Player k has skill level skills[k]. No two players have the same skill level.
The tournament is played in rounds for as long as there are at least two players remaining. In the first round, player 0 faces player 1, player 2 faces player 3, and so on. In the second round, the winner of the match between players 0 and 1 faces the winner of the match between players 2 and 3, and so on. The player with the higher skill level wins the match.
For example, for skills = [4, 2, 7, 3, 1, 8, 6, 5], the tournament is as follows (numbers in circles are skill levels):
round 3: ⑦───final───⑧
╱ ╲ ╱ ╲
round 2: ④ ⑦ ⑧ ⑥
╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲
round 1: ④ ② ⑦ ③ ① ⑧ ⑥ ⑤
──────────────────────
player: 0 1 2 3 4 5 6 7For each player, find the last round in the tournament in which they participate.
Function
solution(skills: int[]) → int[]Examples
Example 1
skills = [4, 2, 7, 3, 1, 8, 6, 5]return = [2, 1, 3, 1, 1, 3, 2, 1]Players 1, 3, 4, and 7 lose in round 1. Players 0 and 6 lose in round 2. Players 2 and 5 reach the final, so their last participation round is 3.
Example 2
skills = [9, 1]return = [1, 1]The only match is the final. Both players participate in round 1, even though player 0 wins the tournament.
Example 3
skills = [1, 4, 3, 2]return = [1, 2, 2, 1]Player 0 loses to player 1, and player 3 loses to player 2 in round 1. Players 1 and 2 meet in round 2, so both have last participation round 2.
Constraints
skills.length >= 2.- For this exercise,
skills.lengthis a power of two. - Every value in
skillsis an integer. - All values in
skillsare distinct.
More DRW Online Assessment questions
- Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
- Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
- Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
- 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
- Nested In-Memory Database TransactionsOA · Seen Aug 2026
- Password Requirement CheckOA · Seen Aug 2026
- Remove Excess Consecutive CharactersOA · Seen Aug 2026
- Shortest Compressed Length After RemovalOA · Seen Jul 2026
- Doctor Appointment Slot AssignmentOA · Seen Jul 2026
- Maximum Even-Sum Neighboring PairsOA · Seen Jul 2026
Similar questions at other companies
- Payment Partner RoutingStripe · OAStripe interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Stabilize Student Test ScoresVirtu Financial · OAVirtu Financial interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Index of the Maximum After Left RotationsChubb · OAChubb interview questions
- Leaves Remaining After WindCresta · OACresta interview questions