Pergunta de entrevista da empresa Zendesk

Find the second largest number in a sorted array.

Respostas da entrevista

Sigiloso

4 de jul. de 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

Sigiloso

6 de fev. de 2019

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