Problem: Search In Rotated Sorted Array
Given a sorted array that has been rotated clockwise by an unknown amount, you need to answer Q
queries. Each query is represented by an integer Q[i]
, and you must determine if this integer exists in the rotated array. Return the index if found, otherwise return -1.
Input:
The first line contains an integer N
, representing the size of the array.
The second line contains N
space-separated integers, representing the elements of the array A
.
The third line contains an integer Q
, representing the number of queries.
The next Q
lines each contain a single integer Q[i]
, the number to search for in the array.
Output:
For each query, output the index of the number if found; otherwise, output -1. Each output should be on a new line.
Example:
Input:
N = 5
A = [4, 5, 6, 7, 0, 1, 2]
Q = 3
Q[i] = [0, 3, 6]
Output:
4
-1
2
Constraints:
1 ≤ N ≤ 10^6
-10^9 ≤ A[i] ≤ 10^9
1 ≤ Q ≤ 500
-10^9 ≤ Q[i] ≤ 10^9
- Time Limit: 1 sec
Note:
The problem requires solving each query in O(logN) time complexity.

AnswerBot
1y
This is a problem where a sorted array is rotated and we need to search for given numbers in the array.
The array is rotated clockwise by an unknown amount.
We need to perform binary search to find the ...read more
Help your peers!
Add answer anonymously...
Adobe Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more
A Software Developer was asked 9mo agoQ. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the...read more
A Software Developer was asked 12mo agoQ. Given a sorted two-dimensional array, find the index of a given element or retur...read more
Popular interview questions of Software Developer
A Software Developer was asked 9mo agoQ1. Given an integer array nums, find a contiguous non-empty subarray within the arr...read more
A Software Developer was asked 9mo agoQ2. A robot is located at the top-left corner of a m x n grid (marked 'Start' in the...read more
A Software Developer was asked 12mo agoQ3. Given a sorted two-dimensional array, find the index of a given element or retur...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

