employer cover photo
employer logo
employer logo

Innominds Software

Is this your company?

Innominds Software interview question

Write program for 2nd largest number without using inbuilt function and without more than 1 loop?

Interview Answers

Anonymous

13 May 2022

import sys a=[int(x) for x in input().split()] #To take all user inputs max1=a[0] max2= -sys.maxsize # to initialize max2 as minimum #oly one loop for i in a: if i > max1: max1,max2 = i,max1 if i max2: max2 = i print(max2)

Anonymous

13 May 2022

#WHY THE HELL THIS COMMENT BOX DELETES MY INDENTATION ?? LOL # JUST DELETE THOSE "----" and add tab for indentation, apologies... import sys a=[int(x) for x in input().split()] max1=a[0] max2= -sys.maxsize for i in a: ----if i > max1: --------max1,max2 = i,max1 ----if i max2: --------max2 = i print(max2)