Pergunta de entrevista da empresa 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?

Respostas da entrevista

Sigiloso

21 de out. de 2010

linear solution if you track highest and secondHighest with integer variables

1

Sigiloso

26 de nov. de 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.