O(N^2) -> O(NlogN) -> O(N)
```\nclass Solution {\npublic:\n    //T.C. : O(N^2)\n    bool solve(string &s,int idx,int mini,int maxi)\n    {\n        if(idx >= s.size())\n            return
```\nclass Solution {\npublic:\n    //T.C. : O(N^2)\n    bool solve(string &s,int idx,int mini,int maxi)\n    {\n        if(idx >= s.size())\n            return false;\n        if(idx == s.size()-1)\n           return true;\n        int si = s.size()-1;\n        int l = idx+mini;\n        if(l > si)\n            return false;\n        int r = min(idx+maxi,si);\n        for(int i=l;i<=r;i++)\n        {\n            if(s[i] == \'0\')\n            {\n            bool a1 = solve(s,i,mini,maxi);\n            if(a1 == true)\n                return true;\n            }\n        }\n        return false;\n        \n    }\n    \n    //T.C. : O(NLogN)\n    bool solve2(string s, int mini, int maxi)\n    {\n        int si=s.size();\n        set<int>st;\n        st.insert(s.size()-1);\n        for(int i=s.size()-1;i>=0;i--)\n        {\n            if(s[i] == \'0\')\n            {\n               if(i+mini >= si)\n                   continue;\n               int find = *lower_bound(st.begin(),st.end(),i+mini);\n               if(find <= i+maxi)\n                   st.insert(i);\n            }\n        }\n        if(st.find(0) == st.end())\n            return false;\n        return true;\n    }\n    \n    //TC : O(N)\n    bool canReach(string s, int mini, int maxi) {      \n        if(s[s.size()-1] != \'0\')\n            return false;\n        int curmaxi=0,si=s.size()-1;\n        queue<int>q;\n        q.push(0);\n        while(!q.empty())\n        {\n            int top = q.front();\n            q.pop();\n            if(top == s.size()-1)\n                return true;\n            for(int i = max(top+mini,curmaxi);i <= min(si,top+maxi);i++)\n            {\n                if(s[i] == \'0\')\n                    q.push(i);\n            }\n            curmaxi = top+maxi+1;\n        }\n        return false;\n    }\n};\n
['C']