Adobe Interview Question

Find the minimum element in a rotated array in O(log n) time.

Interview Answer

Anonymous

Nov 1, 2014

int find(int[] A) { int l = 0, r = A.length - 1; int res = Integer.MAX_VALUE; while (l = A[l]) { res = Math.min(res, A[l]); l = m + 1; } else { res = Math.min(res, A[m]); r = m - 1; } } return res; }

2