My code is providing wrong answer

Hey Sukriti,
The implementation you are applying is not appropriate for the array given in input.
Instead of using this condition in your program
else if(a[mid]>key)

    {

        if(a[mid]>a[i])

            j=mid-1;

        else

            i=mid+1;

    }

I’ll suggest you to use this one
if(a[i]>=a[mid]) {

      if(key>=a[mid]  && key<=a[j])  {

        i=mid+1; 

      }

      else {

        j=mid-1;

      }  

     }

to check key in sorted part
and instead of using this
else

    {

        if(a[mid]<a[j])

            i=mid+1;

        else

            j=mid-1;

    }

use this
if(a[i]<key && key<=a[mid]) {

     j=mid-1;

    }

to check key in un-sorted part
Thank you

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.