Binary Search + Sliding Window (MENTOSS ZINDAGIIIIII)
\n\n# Complexity\n- Time complexity:O(n*log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(
\n\n# Complexity\n- Time complexity:O(n*log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(int wins,vector<int>&v,int maxcost){\n        int i=0,j=0;\n        int n=v.size();\n         int sum=0;\n        while(j<n){\n            sum+=v[j];\n\n            if(j-i+1<wins)\n            j++;\n\n            else{\n                if(sum<=maxcost)\n                return true;\n\n                sum-=v[i];\n                j++;\n                i++;\n            }\n        }\n\n        return false;\n    }\n    int equalSubstring(string s, string t, int maxCost) {\n        int n=s.size();\n        vector<int> v;\n        for(int i=0;i<n;i++){\n            v.push_back(abs(s[i]-t[i]));\n        }\n\n        int lo=0,hi=n;\n        int ans=0;\n        while(lo<=hi){\n            int mid=(lo+hi)/2;\n\n            if(check(mid,v,maxCost)){\n                ans=mid;\n                lo=mid+1;\n            }\n            else hi=mid-1;\n        }\n\n        return ans;\n\n    }\n};\n```
['Binary Search', 'Sliding Window', 'C++']