employer cover photo
employer logo
employer logo

Oculus VR

Acquired by Meta

Is this your company?

Oculus VR interview question

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).

Interview Answer

Anonymous

14 Jan 2016

#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).

1