Search in sorted and rotated array

#include
using namespace std;

int sortedandrotated(int arr[],int s,int end, int c)
{

if(s>end)
{
  return -1;
}

while(s<=end)
{
int mid=(s+end)/2;
if(arr[mid]==c)
{
	return mid;
}

if(arr[s]<arr[mid])
{
	if(c>=arr[s] && c<=arr[mid])
	{
   return sortedandrotated(arr,s,mid-1,c);     
	}

	else
	{
		       return sortedandrotated(arr,mid+1,end,c);     

	}
}

}}

int main() {

int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
	cin>>arr[i];
}

int c;
cin>>c;
int s=0;
int end=n-1;

int ans=sortedandrotated(arr,s,end,c);

cout<<ans;
return 0;

}

@arsh_goyal
hello arsh,
please save ur code here ide.codingblocks.com and share the generated link

@arsh_goyal
you didnt added condition for arr[s] > = arr[mid] in ur sortedandrotated function

image

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.