Search In Rotated Sorted Array Problem Statement
Given a rotated sorted array ARR
of size 'N' and an integer 'K', determine the index at which 'K' is present in the array.
Note:
1. If 'K' is not present in ARR, return -1.
2. The array contains no duplicate elements.
3. ARR is only rotated to the right.
Input:
The first line contains an integer 'T', the number of test cases.
Each test case contains:
- Two space-separated integers 'N' and 'K'.
- A line with 'N' space-separated integers representing the elements of ARR.
Output:
For each test case, output the index where 'K' is found in ARR.
Example:
Suppose ARR = [12, 15, 18, 2, 4] and K = 2. The index where K is present in the array is 3 (0-indexed).
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 5000
0 ≤ K ≤ 105
0 ≤ ARR[i] ≤ 105
AnswerBot
1d
Given a rotated sorted array, find the index of a given integer 'K'.
Perform binary search to find the pivot point where the array is rotated.
Based on the pivot point, apply binary search on the approp...read more
Help your peers!
Add answer anonymously...
Top VMware Software Staff Engineer interview questions & answers
Popular interview questions of Staff Engineer
>
VMware Software Staff Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app