Ranking by likes
Write code · Medium · §6.1 Putting things in order
likes holds the number of likes each post received. likes[i] is the number of likes for post i.
Complete the function solution, which returns a list of the post numbers in order from the most likes to the fewest. If two posts have the same number of likes, the smaller post number comes first.
Function
solution(likes)
Constraints
- The length of
likesis from 1 to 100,000. - The number of likes for each post is an integer from 0 to 1,000,000.
Examples
| likes | result |
|---|---|
[5, 9, 5, 1] | [1, 0, 2, 3] |
[0] | [0] |
Starter code
def solution(likes):
answer = []
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.