BinarySearch
Idenitification
-
If the array given is SORTED,then always go for Binary Search approach.
-
Mid can be calculated as:
mid= start + (end-start)/2
Instead of start+end /2 to avoid Integer overflow (testcases have these)
- For types of problems involving rotated sorted array or find element in such a rotated sorted array ,thumb rule to remember
And once you get the min element and its index u can use that as starting mid and apply binarySearch from there.
No of rotations = index of minimum element