Welcome to the daily solving of our PROBLEM OF THE DAY with Soham Mukherjee. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Divide and Conquer but also build up problem-solving skills.
Given a sorted and rotated array arr of n distinct elements which may be rotated at some point, and given an element key, the task is to find the index of the given element key in the array arr. The whole array arr is given as the range to search.
Rotation shifts elements of the array by a certain number of positions, with elements that fall off one end reappearing at the other end.
Note:- 0-based index is followed & return -1 if the key is not present.
Examples :
Input: arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}, key = 10
Output: 5
Explanation: 10 is found at index 5.
Problem Link: https://practice.geeksforgeeks.org/problems/search-in-a-rotated-array4618/1