+ 3

Second largest...

Problem Statement It's your friend Alan's marriage. As Alan wanted, he wants his best man to be the tallest guy in the group. So, he prepared a list of his friends' heights and has trusted you with the list. It so happened that Danny, the tallest guy in the group, is down with fever and supposedly won't be able to attend the function. So now, its up to you to select the second tallest guy for the status of the best man. To find a quick answer to this, you write a Python script. How would you go about that? Input Format A single line containing the heights of all friends in inches; separated by commas. Constraints 1 <= height of all friends <= 200 Output Format Print the height of the second tallest guy. Evaluation Parameters Sample Input: 142,321,78,32,112,98 Sample Output 142 My attempt https://code.sololearn.com/cdvRx6nb669b/?ref=app

6th Oct 2021, 6:23 AM
Manoj Kumar T
Manoj Kumar T - avatar
4 Respuestas
+ 4
Hey buddy, there were quite some errors in your code. But, even without them your code would be incorrect as you can't even know if the array you entered is more than 2 elements big. In addition you used incorrect input format.(With the problem you posted there is no need for entering array size beforehand.) But I believe this way is way more efficient, as it doesn't require going through the list twice: https://code.sololearn.com/cjgo63wdCX23/?ref=app
6th Oct 2021, 6:52 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
Who came up with those sample numbers? Not only is the tallest guy in the sample input 8.15 meters tall, his height also exceeds the constraint by 121 inches. 😂
6th Oct 2021, 6:29 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Yeah buddy 😊 ur absolutely right... 👍,,,, Nice explanation thank you ☺️❤️
6th Oct 2021, 7:02 AM
Manoj Kumar T
Manoj Kumar T - avatar