Sollicitatiegesprek voor de functie Computer Vision Engineer


Oculus VR

Given a set of numbers, find the pair of numbers that has maximum difference and also the second number appears after the first one. Time complexity needs to be O(n).


Antwoord op sollicitatievraag

1 Antwoord


#def max(a, b) (a>=b ? 1:2) #def min(a, b) (a= temp) { minimum = temp; imin = i+1; } } else { temp = A[i]; if (m >= temp) { minimum = temp; imin = i+1; } } } } Finally, the values in maximum and minimum will be the pair of numbers with the greatest difference between them, with their corresponding indices stored in imax and imin. The complexity of this implementation is O(n) because the loop goes through n-1 elements once, where n is the total number of elements. Strictly speaking, complexity is O(n-1).

Anoniem op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.