class Solution {
public:
bool canReach(vector<int>& arr, int start) {
if(arr[start] == 0) {
return true;
}
int n = arr.size();
vector<bool> visited(n);
queue<int> q;
q.push(start);
visited[start] = true;
while(!q.empty()) {
int i = q.front(); q.pop();
if (arr[i] == 0) {
return true;
}
int next_right = i + arr[i];
if (next_right < n && !visited[next_right]) {
q.push(next_right);
visited[next_right] = true;
}
int next_left = i - arr[i];
if (next_left >= 0 && !visited[next_left]) {
q.push(next_left);
visited[next_left] = true;
}
}
return false;
}
};