Dsa
Binary Search
Medium
Find Position in Rotated Sorted Array
You are given a rotated sorted array of distinct integers and a target value. Write a function to determine the index of the target in the array. If the target is not found, return -1.
Input Format:
- The first line contains an integer n, the size of the array.
- The second line contains n distinct integers, representing the rotated sorted array.
- The third line contains the target integer.
Output Format:
- Print the index of the target if found, otherwise print -1.
Example:
Input:
7
4 5 6 7 0 1 2
0
Output:
4
Key concepts
binary_searcharrayssorting
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