employer cover photo
employer logo
employer logo

Raja Software Labs

Is this your company?

Raja Software Labs interview question

Find second largest element in the array

Interview Answers

Anonymous

10 June 2022

def secondmax(arr): sublist = [x for x in arr if x < max(arr)] return max(sublist) if __name__ == '__main__': arr = [10, 20, 4, 45, 99] print(secondmax(arr))

Anonymous

28 July 2022

private static void printSecondHighest(int[] arr) { int first = Integer.MIN_VALUE; int second = Integer.MIN_VALUE; for(int num: arr){ if(num > first){ second = first; first = num; } else if(num second){ second = num; } } System.out.println(second); }