In this tutorial, we will solve a Hacker rank Find the runner-up problem!
Given the participants’ score sheet for your University Sports Day, you must find the runner-up score. You are given n scores. Store them in a list and find the score of the runner-up.
The first line contains n. The second line contains an array A[] of n integers are each separated by a space.
2 ≤ n ≤ 10
-100 ≤ A[i] ≤ 100
Print the runner-up score.
5
2 3 6 6 5
5
The given list is [2, 3, 6, 6, 5]. The maximum score is 6, the second maximum score is 5. Hence, we print 5 as the runner-up score.
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
arr1 = set(arr)
arr2 = sorted(arr1)
print(arr2[-2])
Step 1: First n will take an integer type input of n scores.
Step 2: then, arr will make a list of these n scores.
Step 3: After this, we converted our list to set so, it will not store multiple same integers.
Step 4: then, I sorted my list of scores.
Step 5: In the last step I printed the second-last integer of my list. And, it is the runner-up score.
Trainings :
Data Science Training in Indore | Python Training in Indore | Data Analytics Training in Indore | Blockchain Training in Indore | React JS Training in Indore | Web Development Training in Indore | Full Stack Development Training in Indore |Free Courses and Resource :
Dart | OpenCV Tutorials | Projects | Interview Questions | Python Data Structures and Algorithms | Aptitude Tests | Verbal Aptitude | Matplotlib Tutorials | Examples | Interview Questions | HackerRank Python | Pandas Tutorials | Projects | Interview Questions | Rust Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | MongoDB Tutorials | Examples | Interview Questions | HackerRank C Program Solutions | Python Tutorials by CodersDaily | React.js Tutorials | Golang Tutorials | Projects | Interview Questions | MS Sql Server Tutorials | Examples | Interview Questions | Verbal Ability Tutorial | Numpy Tutorials | Projects | Interview Questions | Power BI Tutorials | Projects | Interview Questions | Example Dashboards | Tensor Flow | HackerRank C++ Solutions | Django REST Framework Tutorial | CodeChef Python Solutions | Leetcode Python Solutions | Reasoning Ability Tutorial | Quantitative Ability Tutorial | C++ Tutorials | HackerRank Java Solutions | TCS NQT Mock Test Series | Verbal Aptitude 2 | HackerRank DSA Solutions | HackerRank SQL Solutions | Javascript | Node.js Tutorials |Interview Questions :
Pandas Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial |Top Colleges in India :
Indian Institute of Technology Bombay | Jaypee University of Engineering and Technology - Guna |