Question d’entretien chez Amazon

Given the function prototype for a function called secondLargest given a pointer to a list of integers, write down on a piece of paper how you would implement this function and read it back to me. Follow up questions included what is the complexity of your algorithm (O notation)? How would you extend it to do nthLargest element?

Réponses aux questions d'entretien

Utilisateur anonyme

21 oct. 2010

linear solution if you track highest and secondHighest with integer variables

1

Utilisateur anonyme

26 nov. 2009

My solution was to sort the list in descending order and quickly traverse the list for the second largest integer. Complexity would be the time it would take to sort the list.