HackerRank Find the Runner Up Score solution in python

In this HackerRank Find the Runner Up Score problem solution we need to develop a python program that can take an integer and array of values as an input and from the array we need to print the second-highest number. 

Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

def max(l):
    return sorted(set(l))[-2]

test = int(raw_input())
l = [int(_) for _ in raw_input().split()]
print max(l)

Problem solution in Python 3 programming.

if __name__ == '__main__':
    n = int(input())
    arr = map(int, input().split())
    arr = list(arr)
    x = max(arr)
    y = -9999999
    for i in range(0,n):
        if arr[i]<x and arr[i] > y:
            y = arr[i]

Problem solution in pypy programming.

if __name__ == '__main__':
    n = int(raw_input())
    arr = map(int, raw_input().split())
    Max = max(arr)
    while max(arr) == Max:
    print max(arr)

Problem solution in pypy3 programming.

if __name__ == '__main__':
    n = int(input()) 
    #print (input().split())
    #arr = [int(x) for x in input().split()]
    #print (list(input()))
    arr = list(map(int, input().split()))
    #print (arr)
    #arr = sorted(arr)
    #print (arr)
    for i in range(n-1, -1, -1):
        if arr[i]<arr[n-1]:
            temp = arr[i]
    print (temp)
    #print (arr[n-1])

Post a Comment


  1. In the Python 3 code, we just need upto -58 value for the code since the lowest in the test values is -57 (test case 1)

    1. Hi may i know that value must be lesser than the max value but lesser than the lowest test value wouldnt any value in between those number qualify?