Posted on

Description

Submission

class Solution {
    int visited[50001];

public:
    bool canReach(vector<int>& arr, int start) {
        if(start < 0 || start >= arr.size()) return false;
        if(arr[start] == 0) return true;
        if(visited[start]) return false;
        visited[start] = true;

        return canReach(arr, start - arr[start]) || canReach(arr, start + arr[start]);
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *