Zendesk Interview Question

Find the second largest number in a sorted array.

Interview Answers

Anonymous

Jul 4, 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

Anonymous

Feb 6, 2019

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