➜ ~

Playing Hacks and Stuffs!


Project maintained by h4ckyou Hosted on GitHub Pages — Theme by mattgraham

Hackerrank: Runner-Up

Description:

Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score.
You are given scores.
Store them in a list and find the score of the runner-up. 

image

Input Format:

The first line contains n.
The second line contains an array of integers each separated by a space.

Constraints:

- 2 ⩽ n ⩽ 10
- -100 ⩽ A[i] ⩽ 100

So our goal is to find the second runner up in a given number of scores

There are various ways to solve this

But here’s my own thought solution process

My solution involves:

Here’s my solve script

def getRunnerUp(array, N):
    difference = [(N - j) for j in array]
    maxValue = min(difference)
    exclusiveMax = [i for i in difference if i != maxValue]
    minimum = min(exclusiveMax)
    idx = difference.index(minimum)

    return array[idx]

if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))

    result = getRunnerUp(arr, max(arr))
    print(result)

It works! image