It depends "highly" on the language used doesn't it?
Based on the problem as stated
I'd assume no prior knowledge of the rotation amount or direction.
Unless the array is known/assumed to be very large, the simplest
solution is likely the best. Anything else may not qualify under the
"elegan
Modified Piyush's soln to handle the above case.
int get_pivot(int a [ ],int low, int high)
{
if (low < high)
{
int mid = (low+high)/2;
if(a[mid]>a[mid+1])
return mid+1;
if(a[low]>a[mid])
return (get_pivot(a,low,mid-1));
else
It won't work if we rotate the array by 0. So is that the xtra case do
we have to consider???
On May 28, 7:18 pm, Piyush Sinha wrote:
> The main idea is to get the point at which the the rotation is
> made...It can be done in O(lgN) time complexity...
>
> int get_pivot(int a [ ],int low, int high
ok... seems fine. thanx!
On May 28, 7:18 pm, Piyush Sinha wrote:
> The main idea is to get the point at which the the rotation is
> made...It can be done in O(lgN) time complexity...
>
> int get_pivot(int a [ ],int low, int high)
> {
> int mid = (low+high)/2;
> if(a[mid]>a[mid+1])
>