Frage im Vorstellungsgespräch bei American Express

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

Antworten zu Vorstellungsgespräch

Anonym

29. Okt. 2015

I wrote the program

Anonym

4. Sept. 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; }