Search a Rotated Array
A sorted array of distinct values was rotated at an unknown pivot. Find the 1-based position of target T, or −1.
Input: the first line has N and T; the second line has the rotated array.
Output: the position of T, or −1.
Constraints:
- 1 ≤ N ≤ 105
- values distinct, |values| ≤ 106
Sample Tests
Input 1
7 0 4 5 6 7 0 1 2
Output 1
5
Input 2
3 3 3 1 2
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.