Amazon | SDE2 | Onsite - Seattle | Search in different rotated sorted array
Anonymous User
1440

Given a rotated sorted array, search for a target. But the rotated sorted array is little different.

arr = [5,6,7,(4),1,2,3] target = 2
arr = [6,7,(5),1,2,3,4] target = 5

Notice the array. Take 4 (arr1) or 5 (arr2) as pivot and swap the right part to left and vice versa. Then it becomes a sorted array. The pivot can also be the first or last one like below.

arr = [(8),5,6,7] target = 6
arr = [5,6,7,(4)] target = 7

Comments (3)