Simple and fast C++ solution
Intuition\nWe iterate over the input and maintain a [start, i] interval that only contains unique characters. For every character s[i] we first advance start un
# Intuition\nWe iterate over the input and maintain a $$[start, i]$$ interval that only contains unique characters. For every character $$s[i]$$ we first advance $$start$$ until $$[start, i-1]$$ doesn\'t $$s[i]$$. The longest $$i-start+1$$ is the longest substring.\n\n# Complexity\n- Time complexity: $$O(n)$$ (iterate once over the input)\n\n- Space complexity: $$O(1)$$ (space needed doesn\'t depend on input size)\n\n# Code\n```\nclass Solution {\npublic:\n    int lengthOfLongestSubstring(string s) {\n\t\t\tif (s.empty()) return 0;  \n\t\t  int result = 0;  // Length of longest substring found so far.\n\t\t  int start = 0;  // Start index of current substring with unique characters.\n\t\t\t// Track if a character is in [start, i]. `char` is 8-bit (hence 256 possibilties).\n\t\t\t// More generic, but slower, would be a std::unordered_set<char>.\n\t\t  std::vector<bool> chars_in_substring;\n\t\t  chars_in_substring.resize(256);\n\t\t  for (int i = 0; i < s.size(); ++i) {\n\t\t\t\t// Advance `start` until [start, i] contains only unique characters.\n\t\t\t\t// This means s[i] cannot be in [start, i-1].\n\t\t\t  while (chars_in_substring[s[i]]) {\n\t\t\t\t  chars_in_substring[s[start++]] = false;\n\t\t\t  }\n\t\t\t  chars_in_substring[s[i]] = true;\n\t\t\t\t// Is this our new longest substring?\n\t\t\t  result = std::max(result, i-start+1);\t\n\t\t  }\n\t\t  return result;\n    }\n};\n```
['C++']