Find the Runner-Up Score!

Sort by

recency

|

8382 Discussions

|

  • + 0 comments

    if name == 'main': #bharat n = int(input()) arr = map(int, input().split()) Max,secondMax=-101,-101 for x in arr: if(x>Max): secondMax=Max
    Max=x
    elif(x>secondMax and x

  • + 0 comments

    Sorted and list looks easy and simple but you're taking a toll on space and time. Any interviewer seeing this code will make question you. Always use less time and space solutions. Here is my O(n) Time and O(1) space solution.

    if __name__ == '__main__':
        n = int(input())
        arr = map(int, input().split())
        Max,secondMax=-101,-101
        for x in arr:
            if(x>Max):
                secondMax=Max  
                Max=x   
            elif(x>secondMax and x<Max):
                secondMax=x
        print(secondMax)
    
  • + 0 comments

    if name == 'main': n = int(input()) # number of scores arr = list(map(int, input().split())) # scores list

    # Remove duplicates and sort
    unique_scores = sorted(set(arr), reverse=True)
    
    # Runner-up score = second element in sorted unique list
    print(unique_scores[1])
    
  • + 0 comments

    if name == 'main': n = int(input()) arr = map(int, input().split()) arr=set(arr) arr=list(arr) arr.sort() print(arr[-2])

  • + 0 comments

    if name == 'main': n = int(input()) arr = map(int, input().split()) arr=set(arr) arr=list(arr) arr.sort() print(arr[-2])