Is this your company?
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).
Anonymous
#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).
Check out your Company Bowl for anonymous work chats.