[Java/C++/Python] One Pass DP
Explanation\ndp[i] = true if we can reach s[i].\npre means the number of previous position that we can jump from.\n\n\n# Complexity\nTime O(n)\nSpace O(n)\n\n\n
# **Explanation**\n`dp[i] = true` if we can reach `s[i]`.\n`pre` means the number of previous position that we can jump from.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public boolean canReach(String s, int minJ, int maxJ) {\n        int n = s.length(), pre = 0;\n        boolean[] dp = new boolean[n];\n        dp[0] = true;\n        for (int i = 1; i < n; ++i) {\n            if (i >= minJ && dp[i - minJ])\n                pre++;\n            if (i > maxJ && dp[i - maxJ - 1])\n                pre--;\n            dp[i] = pre > 0 && s.charAt(i) == \'0\';\n        }\n        return dp[n - 1];\n    }\n```\n\n**C++**\n```cpp\n    bool canReach(string s, int minJ, int maxJ) {\n        int n = s.size(), pre = 0;\n        vector<bool> dp(n, false);\n        dp[0] = true;\n        for (int i = 1; i < n; ++i) {\n            if (i >= minJ)\n                pre += dp[i - minJ];\n            if (i > maxJ)\n                pre -= dp[i - maxJ - 1];\n            dp[i] = pre > 0 && s[i] == \'0\';\n        }\n        return dp[n - 1];\n    }\n```\n\n**Python**\n```py\n    def canReach(self, s, minJ, maxJ):\n        dp = [c == \'0\' for c in s]\n        pre = 0\n        for i in xrange(1, len(s)):\n            if i >= minJ: pre += dp[i - minJ]\n            if i > maxJ: pre -= dp[i - maxJ - 1]\n            dp[i] &= pre > 0\n        return dp[-1]\n```\n
[]