Question d’entretien chez Zendesk

Find the second largest number in a sorted array.

Réponses aux questions d'entretien

Utilisateur anonyme

4 juil. 2017

Do you mean unsorted? If not, wouldn't this just be second last index (assuming ascending order sorted)? If this was unsorted, one could sort the array then take second last element. However, there is a quicker way of doing this which is to use quickselect algorithm.

2

Utilisateur anonyme

6 févr. 2019

def second_highest(arr) arr[-2] end second_highest([1,2,3,4,5])