DIFFICULTY
  • School
  • Basic
  • Easy
  • Medium
  • Hard
STATUS
  • Solved
  • Unsolved



Loading...

Leaderboard
Showing:
Search an element in sorted and rotated array
Easy Accuracy: 50.0% Submissions: 11693 Points: 2

Given a sorted and rotated array A of N distinct elements which is rotated at some point, and given an element K. The task is to find the index of the given element K in the array A.

Example 1:

Input:
N = 9
A[] = {5 6,7,8,9,10,1,2,3}
K = 10
Output: 5
Explanation: 10 is found at index 5.

Example 1:

Input:
N = 3
A[] = {3,1,2}
K = 1
Output: 1

User Task:
Complete Search() function and return the index of the element K if found in the array. If the element is not present, then return -1.

Expected Time Complexity: O(log N).
Expected Auxiliary Space: O(1).

Constraints:
1 ≤ N ≤ 107
0 ≤ Ai ≤ 108
1 ≤ K ≤ 108

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Search an element in sorted and rotated array

Output Window