➤ Problem Link : 500A. New Year Transportation
✅ C++ Solution :
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t;
cin>>n>>t;
int arr[n];
for(int i=1;i<n;i++)
cin>>arr[i];
bool f=0;
int val=1;
while(val<=t)
{
val=val+arr[val];
if(val==t)
{
f=1;
break;
}
}
if(f)
cout<<"YES";
else
cout<<"NO";
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
