Code for solving the question by other way

In the lecture, one other way to solve this question is mentioned i.e by dividing the array into two equal parts and then checking if both parts are sorted. Could you please send a code for it?

hello @anshufirefox

its simple .

bool iSorted(int *a,int s,int e){    // s and e are starting and ending index of array a
       if(s>=e){   // single element so already sorted return true.
           return true;
      }
    int mid=(s+e)/2;  
    bool left=false,right=false;
    left=isSorted(a,s,mid);
    right=isSorted(a,mid+1,e);
   
return left && right && a[mid]<=a[mid+1];



}

Thank You, I understood it. :slight_smile:

Can I help you by rating you somehwere? Please send the link :slight_smile: :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.

u can use that link to give rating and feedback

Yeah, I just did that. Thanks a lot, Aman bhaiya.

1 Like