/*
Problem Statement:
Given an array, find out how many times it has to been rotated
from its initial sorted position.
Input-Output:
Eg. [11,12,15,18,2,5,6,8]
It has been rotated: 4 times
(One rotation means putting the first element to the end)
Note: The array cannot contain duplicates
Logic:
The position of the minimum element will give the number of times the array has been rotated
from its initial sorted position.
Eg. For [2,5,6,8,11,12,15,18], 1 rotation gives [5,6,8,11,12,15,18,2], 2 rotations [6,8,11,12,15,18,2,5] and so on.
Finding the minimum element will take O(N) time but, we can use Binary Search to find the mimimum element, we can reduce the complexity to O(log N).
If we look at the rotated array, to identify the minimum element (say a[i]), we observe that a[i-1]>a[i]a[mid-1] && a[mid]a[mid-1] && a[mid]>a[mid+1])
{
low = mid-1;
}
}
return mid;
}
}