All the elements in the array are distinct.
Input: arr = [3,4,5,1,2]
Output: 1
Explanation: The original array was [1,2,3,4,5] and it was rotated 3 times.
The first line contains an integer 'n', the size of the array.
The second line contains 'n' space-separated integers.
The only line contains the minimum number in the given array.
You donβt need to print anything; It has already been taken care of. Just implement the given function.
The basic approach to find the minimum element is to traverse the whole array and keep updating the minimum value as we traverse that array.
Example: 3 4 1 2
Initialize min = 3 and start traversing the array. When we reach 4 we see that 4 > 3 hence we donβt update min. Now we see that 1 < 3, therefore we update min. Now min = 1. Now finally we reach 2 and we see that 2 > 1, hence we donβt update min. Now we have reached the end of the array, hence we print our answer(min), which is equal to 1.
As it is given in the hint itself, we want to decrease the search space in order to optimize our solution. Hence we want to apply the technique of divide and conquer for this. Here use a binary search algorithm to do so.