0

Find second Largest number in a list.

find second largest number in a list, would be very easy if we use Max and sort. But finding it without using built-in functions, also a catch which makes the problem interesting is that u can iterate over the list only once. Have tried it, but failed at iterating over the list once. Any other approaches..Thanks https://code.sololearn.com/cm2t5tscw58z/?ref=app

27th Jul 2018, 8:04 AM
Saumya Katiyar
Saumya Katiyar - avatar
2 Respostas
+ 1
you could do two variables to store highest and second highest and do if statements that compares if its higher that highest and higher than second highest in the stored variables. and if the iterated element is higher than one of them, replace the variable value(s).
27th Jul 2018, 9:14 AM
Markus Kaleton
Markus Kaleton - avatar
0
Saumya Katiyar cannot do it iterating only once, but can do it iterating twice through the list.I think its not possible to solve by iterating it only once but I am not sure.
27th Jul 2018, 8:32 AM
Pulkit Kamboj
Pulkit Kamboj - avatar