Pergunta de entrevista da empresa Payoneer

Find the second biggest number in array

Resposta da entrevista

Sigiloso

23 de ago. de 2020

1) Initialize two variables first and second to INT_MIN as first = second = INT_MIN 2) Start traversing the array, a) If the current element in an array say arr[i] is greater than first. Then update first and second as, second = first first = arr[i] b) If the current element is in between first and second, then update second to store the value of the current variable as second = arr[i] 3) Return the value stored in the second. Time Complexity: O(n). Only one traversal of the array is needed. Auxiliary space: O(1). As no extra space is required.