May-24-2019, 09:31 AM
The task is to find the second largest number in an array.
For eg
INPUT: 5
1, 4, 5, 5, 3
OUTPUT: 4
I tried the following code, but it shows up an error that map() has no len().
For eg
INPUT: 5
1, 4, 5, 5, 3
OUTPUT: 4
I tried the following code, but it shows up an error that map() has no len().
def runner_up(arr): a = max(arr) for i in range(len(arr)): if arr[i] == a: arr.remove(a) #remove all the maximum values. There can be more than one return max(arr) size_of_arr = int(input()) arr = map(int, input().split()) print (runner_up(arr))If I don't use map, I will not be able to take the input and if I use map, I will not be able to get the length of the array. What should I try? I will like to know how to fix my code and also if there are any other methods to solve this problem.