Find the Runner-Up Score! | HackerRank
Find the Runner-Up Score! | HackerRank
For a given list of numbers, find the second largest number.
www.hackerrank.com
Goal
1. Give n scores
2. Store them in a list
3. find the score of the runner-up
so, you should print the runner-up score.
Solution
You can convert map into list.
After then sort asending order and then convert list to set because you need to escape duplicate scores
You can print runner-up score with index -2 because negative indexing is used in Python to begins slicing from the end of list. So in our case, you need to read index -2.
# Find the Runner-Up Score!
if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
list_arr = list(arr)
list_arr.sort()
convert_arr = list(set(list_arr))
print(convert_arr[-2])
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
[Python] HackerRank - Finding the percentage (0) | 2023.02.01 |
---|---|
[Python] HackerRank - Nested Lists (0) | 2023.01.31 |
[Python] HackerRank -List Comprehensions (0) | 2023.01.28 |
[Python] HackerRank - Print Function (0) | 2023.01.27 |
[Python] HackerRank - Write a function (0) | 2023.01.26 |