Dsa
Binary Search
Medium
Rotated Sorted Array Search
You are given a rotated sorted array 'nums' where n is the length of the array and an integer 'target'. Return the index of 'target' if it is in the array, or -1 if it is not. The input array is guaranteed to contain no duplicates.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^6), the size of the array.
- The second line contains n space-separated integers representing the rotated sorted array.
- The third line contains the target integer (0 ≤ target ≤ 10^9).
Output format:
- Print a single integer, the index of target or -1 if not found.
Example:
Input:
5
4 5 6 7 0 1 2
0
Output:
4
Key concepts
binary_searcharrayrotation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now