The code is not running for a fully rotated array or an unrotated array

the code mentioned in the video is giving -1 for the array which is completely sorted. is pivot meaningless for a sorted array?
according to me, it should still return the greatest element in the array.

Hi @sirraghavgupta, pivot element is that element in an array for which the next number is smaller than it. Mathematically it is:

Pivot Element is a[i] iff
a[i] > a[i+1] ∀ i ∈ [0,n-1] : //n is size of array

In a completely sorted there is no element or i which satisfies the above condition. i.e. there’s no pivot element and hence we get -1.

Hope this helps :slight_smile:

Ok thanks. It is good.