[Java] Sliding window | Aditya Verma
\nclass Solution {\n    public String minWindow(String s, String t) {\n        \n        Map<Character, Integer> map = new HashMap<>();\n        for(char ch: t.
```\nclass Solution {\n    public String minWindow(String s, String t) {\n        \n        Map<Character, Integer> map = new HashMap<>();\n        for(char ch: t.toCharArray())\n            map.put(ch, map.getOrDefault(ch, 0) + 1);\n        \n        int count = map.size(), ansLength = Integer.MAX_VALUE;\n        String ans = "";\n        \n        int i = 0, j = 0;\n        while(j < s.length()) {\n            \n            char cur = s.charAt(j);\n            if(map.containsKey(cur)) {\n                map.put(cur, map.get(cur) - 1);\n                if(map.get(cur) == 0) count--;\n            }\n            \n            if(count > 0)\n                j++;\n            \n            else if(count == 0) {  \n                  \n                while(count == 0) {\n                    \n                    if(j-i+1 < ansLength) {\n                        ansLength = j-i+1;\n                        ans = s.substring(i, j+1);\n                    }\n                    \n                    char rm = s.charAt(i);\n                    if(map.containsKey(rm)) {\n                        map.put(rm, map.get(rm) + 1);\n                        if(map.get(rm) == 1) count++;\n                    }  \n                    \n                    i++;    \n                }  \n                \n                j++;  \n            }\n        }\n        \n        return ans;\n         \n    }\n}\n```
['Sliding Window', 'Java']