DEV Community

Cover image for Find the runner up score - HackerRank Python Solution
Deepak Raj
Deepak Raj

Posted on • Originally published at codeperfectplus.com on

Find the runner up score - HackerRank Python Solution

In this tutorial, we will guide you through the process of solving the Find the runner up score programming problem from HackerRank’s “ Python ” domain.

Disclaimer: We encourage you to solve this challenge yourself before reading our tutorial. We have provided a detailed explanation of the problem and our solutions to help you check your work.

Problem Statement

find the runner up score in the given student score list or in simple words find the second maximum number in the array.

Find the runner up score Solution in Python

Explanation

In the above code, we have created a function named find_runner_up_score() that takes a list of numbers as input and returns the second largest number in the list.

  • First, we used the set() function to remove duplicate elements from the list.
  • then we use the sorted() function to sort the list in ascending order.
  • then we use the [-2] index to access the second largest number in the list.

Time Complexity

The time complexity of the above solution is O(n log n) because we are using the sorted() function to sort the list.

Problem statement is taken from Hackerrank, and the solutions are implemented by CodePerfectPlus team

Other Article By Author

30 Days of Code SubReddit

Top comments (0)