Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are N players ( numbered from 0 to N 1 ) participating in a tournament. The K - th player's skill level is skills

There are N players (numbered from 0 to N1) participating in a tournament. The K-th player's skill level is 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. A single round of the tournament consists of one or more matches. In a match, two players compete against each other. The loser is eliminated and the winner advances to the next round. In the first round player 0 faces player 1, player 2 faces player 3, etc. In the second round the winner of the match between player 0 and player 1 faces the winner of the match between player 2 and player 3, etc. 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):
Graphical representation of the first example:
For each player, find the last round in the tournament in which they participate.
Write a function:
function solution(skills: number[]): number[];
that, given an array skills of N integers, returns an array results of N integers, where results[K] denotes the number of the last round in which the K-th player participates.
Examples:
Given skills =[4,2,7,3,1,8,6,5], the function should return [2,1,3,1,1,3,2,1], as described above.
Given skills =[4,2,1,3], the function should return [2,1,1,2].
Given skills =[3,4,2,1], the function should return [1,2,2,1].
Write an efficient algorithm for the following assumptions:
N is an integer power of 2 within the range [2..262,144]; each element of array skills is an integer within the range [1..N]; the elements of skills are all distinct.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Write Hund's rule?

Answered: 1 week ago