Java Simple Sliding Window Technique With Comments
\n\n    public int lengthOfLongestSubstring(String s) {\n        int left = 0; // start of window\n        int right = 0; // end of window (initially the same a
```\n\n    public int lengthOfLongestSubstring(String s) {\n        int left = 0; // start of window\n        int right = 0; // end of window (initially the same as start so we can grab the first char)\n        int result = 0; // var to store the length of the longest substring we have found so far\n        HashSet<Character> chars = new HashSet(); // hashset to track the chars in the current substring\n\t\t// the right hand side of the window must not go over the bounds of the string\n        while(right < s.length()) {\n            // use the right hand side of the window to get the char, it is initialised to 0 so will pick the first character first\n            if(!chars.contains(s.charAt(right))) {\n                chars.add(s.charAt(right));\n\t\t\t\t// if the current set of unique chars is greater in size than the result, that\'s our longest substring\n                result = Math.max(result, chars.size());\n\t\t\t\t// increment right to increase the window size and grab a new char\n                right++;\n            } else {\n\t\t\t// once we encounter a char which is already in the hashset we need create a new window starting from left + 1, and reset right to equal left to initialise a new window\n                left ++;\n                right = left;\n\t\t\t\t// reset our tracker\n                chars.clear();\n            }\n        }\n        return result;\n    }\n\t```
['Sliding Window', 'Java']