Domanda di colloquio di American Express

Write program to find second highest number from a list, without using sorting.

Risposte di colloquio

Anonimo

29 ott 2015

I wrote the program

Anonimo

4 set 2018

public static int secondHighnestNum(int[] array){ if(array == null || array.length == 0) return -1; int first, second; first = second = Integer.MIN_VALUE; for(int i=0; i first){ second = first; first = array[i]; } else if(array[i] > second && array[i] != first){ second = array[i]; } } if(second == Integer.MIN.VALUE){ return -1; } return second; }