Pivot Element showing timelimit error

could you please tell me why this is showing timelimit error https://ide.codingblocks.com/s/77028

Hi @aganunay, the code you have written is incorrect. I suggest you to watch the video of this topic again and then try.
Also I have made the relevant changes and saved them here.
Compare it with your code, the if boundary conditions. But first try the question again.

Hope, this helps :slight_smile:

i rectified my code but now it is showing time limit error also the code which you gave me it shows no output

Hi @proRram, see in binary search one of the motive was to shorten or narrow our search area. When we do this thing this means we alter our boundaries of search area by shifting its starting and ending positions.
But here we check wether pivot element is present in sorted part or unsorted part by comparing it with first and last element of whole array irrespective of search domain.
In retrospect to this we need to check mid < n-1 except checking mid < e in  if  in Line No. 17 of your code.

Hope this helps :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.