0
smaller time complexity. Find number without array
May I ask, is there an algorithm to find the second largest number and the second smallest number? And with the least number of comparisons and the least time complexity? It's one of the exercises on the net. I did it via array, but it seems to use only if else and def, because they have less time complexity. That seems too complicated to me though. Because I would have to do 6 comparisons for each element. When I wouldn't know which number has what value.
2 ответов
+ 5
Only an idea. Idk if it's helpfull.
nums = {3,8,5,0,4}
nums.remove(max(nums))
nums.remove(min(nums))
print(min(nums),max(nums))
# prints ==> 3 5
0
Thanks.
I solve it different way, but this is better