can anyone tell me why #include <bits/stdc++.h>
using namespace std;
bool check(int i,int *ar,int n)
{
if(i<1 &&i>n)
{
return false;
}
else
{
if(ar[i]!=0)
{
bool a=check(i+ar[i],ar,n);
if(a)
{
return true;
}
bool b=check(i-ar[i],ar,n);
return a||b;
}
else{
return true;
}
}
}
int main(){
int n,sv;
cin>>n>>sv;
int ar[n];
for(int i=1;i<=n;i++)
{
cin>>ar[i];
}
int i=sv;
bool ans=check(sv,ar,n);
if(ans==true)
{
cout<<"YES";
}
else
{
cout<<"NO";
}
}it is not paasing all the test cases?