Implement a function lengthOfLongestSubstring that takes a string and returns the length of the longest substring without repeating characters.
Input:
- A single string
s (may contain spaces, letters, digits, or symbols)
Output:
- An integer representing the length of the longest substring without repeating characters
Example Inputs & Outputs
// Example 1:
Input: "abcabcbb"
Output: 3 // "abc"
// Example 2:
Input: "bbbbb"
Output: 1 // "b"
// Example 3:
Input: "pwwkew"
Output: 3 // "wke"
// Example 4:
Input: ""
Output: 0
// Example 5:
Input: "aab"
Output: 2 // "ab"
Constraints & Edge Cases
- Input string may be empty
- Input string can contain any printable characters
- Repeated characters may appear consecutively or at intervals
- Result must be calculated in optimal time (O(n))