C++ beginner friendly solution using set.
Intuition\nGenerally we think of dp solution using for loop between minjump to maxjump, but it results in TLE due its worst time complexity O(n^2).\nSo, some ho
# Intuition\nGenerally we think of dp solution using for loop between minjump to maxjump, but it results in TLE due its worst time complexity O(n^2).\nSo, some how we need to decrease the no. of iterations in the call.\n\n# Approach\nTo decrease the no. of itterations in the call, I used set.\nFirst of all, I inserted all indices that contain \'0\' and then I iterated in the set using lower_bound which need to be less than min(maxjump,s.size()-1). We can erase the index from the set after getting its answer.\nSo, we can decrease the repeating calls/itterations.\n\n# Complexity\n- Time complexity:\napprox O(n*logn);\n\n- Space complexity:\nO(2*n);\n\n# Code\n```\nclass Solution {\npublic:\n    int jg7(int i,string &s,vector<int> &dp,int mj,int maj,set<int> &set){\n        int n=s.size();\n        if(i==n-1)return 1;\n        if(dp[i]!=-1)return dp[i];int a=0,k=min(i+maj,n-1);\n        int b=0;\n        while(1){{\n            auto it=set.lower_bound(i+mj);\n            if(it==set.end() || *it>k)break;\n                auto j=*it;set.erase(j);\n                if(dp[j]==-1)\n                dp[j]=jg7(j,s,dp,mj,maj,set);b=dp[j];\n            }a=(a||b);if(a==1)break;\n        }\n        return dp[i]=a;\n    }\n    bool canReach(string s, int minJump, int maxJump) {\n        int n=s.size();\n        vector<int> dp(n+1,-1);set<int> set;\n        for(int i=0;i<n;i++)if(s[i]==\'0\')set.insert(i);\n        return jg7(0,s,dp,minJump,maxJump,set);\n    }\n};\n```
['String', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++']