Can anyone help me out?

#include <bits/stdc++.h>
using namespace std;
int dp[100000];
bool *visited;
bool check(int i,int *ar,int n)
{
if(i>=0 || i>n)
{
return false;
}

	if(dp[i]!=-1)
	{
		return dp[i];
	}
	
	if(ar[i]==0)
	{
		return true;
	}
    
    if(visited[i])return false;
	visited[i] = 1;
    bool a=check(i+ar[i],ar,n);
    if(a==true)
    {
        return dp[i]=true;
    }
    bool b=check(i-ar[i],ar,n);
    return dp[i]=b;

}
int main(){
int n,sv;
cin>>n>>sv;
int ar[n];

for(int i=1;i<=n;i++)
{
    cin>>ar[i];
    dp[i]=-1;
}
visited=new bool[100000]{0};
int i=sv;
bool ans=check(sv,ar,n);
if(ans)
{
	

	cout<<"YES";
}
else
{
	cout<<"NO";
}
cout<<ans;

}
why this code giving error?

if condition galat hai ismai
if(i<0||i>n) return false; ayga

i have started indexing from 1 then it should be fine

i have started indexing from 1 so it is fine

abhi apka doubt kya hai, …?

can you give me your number?

aksbdfjakhsvdbfkhasvdf-> 8368547890