Second-highest score
Write code · Medium · §3.1 Finding ranks
Complete the function solution, which returns the second-highest score among the distinct scores in the list scores.
If the highest score appears several times, it is counted only once. If there is only one distinct score, return -1.
Function
solution(scores)
Constraints
- The length of
scoresis from 1 to 1,000. - Each score is an integer from 0 to 100.
Examples
| scores | result |
|---|---|
[90, 95, 95, 80] | 90 |
[70, 70] | -1 |
Starter code
def solution(scores):
answer = -1
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.