Use Sliding Window To Get Maximum Window Size | Java | C++
Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/gJQsXRKX7bI\n# Code\nC++\n\nclass Solution {\npublic:\n    int equal
# Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/gJQsXRKX7bI\n# Code\nC++\n```\nclass Solution {\npublic:\n    int equalSubstring(string s, string t, int maxCost) {\n       int leftPtr = 0, size = s.size(), rightPtr = 0;\n       int currCost = 0, maxLen = 0;\n       while(rightPtr < size){\n          currCost += abs(s[rightPtr] - t[rightPtr]);\n          if(currCost > maxCost){\n            while(leftPtr <= rightPtr && currCost > maxCost){\n                  currCost -= abs(s[leftPtr] - t[leftPtr]);\n                  leftPtr++;\n            }\n          }\n          if(leftPtr <= rightPtr){\n            maxLen = max(maxLen, rightPtr - leftPtr + 1);\n          }\n          rightPtr++;\n       }  \n       return maxLen;\n    }\n};\n```\nJava\n```\nclass Solution {\n    public int equalSubstring(String s, String t, int maxCost) {\n        int leftPtr = 0, size = s.length(), rightPtr = 0;\n        int currCost = 0, maxLen = 0;\n        \n        while (rightPtr < size) {\n            currCost += Math.abs(s.charAt(rightPtr) - t.charAt(rightPtr));\n            \n            if (currCost > maxCost) {\n                while (leftPtr <= rightPtr && currCost > maxCost) {\n                    currCost -= Math.abs(s.charAt(leftPtr) - t.charAt(leftPtr));\n                    leftPtr++;\n                }\n            }\n            \n            if (leftPtr <= rightPtr) {\n                maxLen = Math.max(maxLen, rightPtr - leftPtr + 1);\n            }\n            \n            rightPtr++;\n        }\n        \n        return maxLen;\n    }\n}\n\n```
['String', 'Sliding Window', 'C++', 'Java']