99% beat || without DP || O(n) || 92% beat memory.
\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\n
![image.png](https://assets.leetcode.com/users/images/f6d318a2-9e2c-4727-a1ab-332886770394_1705064811.9640832.png)\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution {\n    public boolean canReach(String s, int minJump, int maxJump) {\n        char[] arr = s.toCharArray();\n        if(arr[arr.length-1]==\'1\')\n            return false;\n        int n = arr.length,from = minJump, to = maxJump, min = 0, max = 0, flag = 0, f = 0, lastmin = 0, lastmax = 0, slide1=0,slide2=0;\n        while (to < n) {\n            f = 0;\n            flag = 0;\n            from = min + minJump;\n            if (from < max)\n                from = max;\n            slide1 = min +maxJump;\n            slide2 = max+minJump;\n            to = max + maxJump;\n            if (to > n-1) {\n                for (int k = n-minJump-1; k>=n-maxJump-1 && k>=min; k--) {\n                    if (arr[k] == \'0\') {\n                        from = k;\n                        f = 1;\n                    }\n                }\n                if (f == 1)\n                    return true;\n                else \n                    return false;\n            }\n            for (int i = from; i <= to; i++) {\n                if(i<=slide1|| i>=slide2)\n                if (arr[i] == \'0\') {\n                    if (flag == 0) {\n                        min = i;\n                        flag = 1;\n                    }\n                    max = i;\n                }\n            }\n            if (min == n - 1 || max == n - 1)\n                return true;\n            if (lastmax == max && lastmin == min)\n                return false;\n            lastmax = max;\n            lastmin = min;\n        }\n        return true;\n    }\n}\n```
['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']