I am trying to find second biggest number in a list of numbers. In cases when there a duplicates, the second biggest number will be the second biggest number by value. For example, in a list [3, 2, 7, 7, 5] the second biggest number should be 5.
So here is what I am doing in order to solve it.
def find_second_number(nums):
m1 = sorted(nums)[-1]
m2 = sorted(nums)[-2]
if m1 == m2:
find_second_number(sorted(nums)[:-1])
else:
return m2
return m2
arr = [x for x in (input().split())]
print(find_second_number(arr))
What I don't understand is, which m2 is being returned. I guess in the case when arr = [3, 2, 7, 7, 5], there will be two recursive calls of find_second_number() however, I am confused which instance of the function should return the m2.