Java || HashSet  || Sliding Window
Intuition\nUpon encountering this problem, my initial instinct is to utilize the sliding window technique to identify the length of the longest substring withou
# Intuition\nUpon encountering this problem, my initial instinct is to utilize the sliding window technique to identify the length of the longest substring without repeating characters.\n\n# Approach\nMy approach to tackling this problem involves implementing the sliding window technique to ascertain the length of the longest substring that does not contain any repeated characters. To do so, I maintain a HashSet called `uniqueChars` to keep track of the characters present in the current window. Additionally, two pointers named `start` and `end` denote the beginning and end of the present substring segment. Furthermore, a variable named `maxSubstringLength` is utilized to track the length of the longest valid substring.\n\nThe algorithm operates as follows:\n1. While the `end` pointer remains within the bounds of the string:\n   - If the character at the `end` position is not present in the `uniqueChars` set:\n     - Add the character to the set.\n     - Update the `maxSubstringLength` by comparing it to the length of the current substring (`end - start + 1`).\n     - Increment the `end` pointer.\n   - If the character at the `end` position is already in the `uniqueChars` set:\n     - Remove the character at the `start` position from the set.\n     - Increment the `start` pointer to slide the window to the right.\n\nUpon completing the iteration, the algorithm returns the calculated `maxSubstringLength`.\n\nThis sliding window approach efficiently identifies the length of the longest substring without repeating characters, accomplishing the task in a single traversal of the string.\n\n# Complexity\n- Time complexity: O(n)\n  The algorithm traverses the provided string once, performing constant-time operations at each step.\n\n- Space complexity: O(k)\n  The algorithm employs a HashSet named `uniqueChars` to store distinct characters in the current window. In the worst case, the HashSet may contain all characters from the input string, leading to a space complexity of O(k), where k is the size of the character set.\n\n# Code\n```\nclass Solution {\n     public int lengthOfLongestSubstring(String s) {\nHashSet<Character> uniqueChars = new HashSet<>();\n    int start = 0;\n    int end = 0;\n    int maxSubstringLength = 0;\n\n    while (end < s.length()) {\n        if (!uniqueChars.contains(s.charAt(end))) {\n            uniqueChars.add(s.charAt(end));\n            maxSubstringLength = Math.max(maxSubstringLength, end - start + 1);\n            end++;\n        } else {\n            uniqueChars.remove(s.charAt(start));\n            start++;\n        }\n    }\n\n    return maxSubstringLength;\n    }\n}\n```\n![c0504eaf-5fb8-4a1d-a769-833262d1b86e_1674433591.3836212.webp](https://assets.leetcode.com/users/images/8a3b41d1-f0ca-472f-a9f7-8346b34a824e_1693297402.2918687.webp)
['Java']