Given a string, find the length of the longest substring without repeating characters.

Function Signature:

def length_of_longest_substring(s: str) -> int:
    """
    Find the length of the longest substring without repeating characters.

    Parameters:
    - s: Input string.

    Returns:
    - int: Length of the longest substring without repeating characters.
    """
    # Your code here

Example:

# Input: s = "abcabcbb"
# Output: 3
# Explanation: The answer is "abc", with the length of 3.

# Input: s = "bbbbb"
# Output: 1
# Explanation: The answer is "b", with the length of 1.

# Input: s = "pwwkew"
# Output: 3
# Explanation: The answer is "wke", with the length of 3.
# Notice that the answer must be a substring, 
# "pwke" is a subsequence and not a substring.

# Input: s = "abcde"
# Output: 5
# Explanation: The answer is "abcde", with the length of 5.

Note:

  • A substring is a contiguous sequence of characters within a string.
  • You may assume that the input string only contains lowercase English letters.

Instructions:

  • Write the length_of_longest_substring function to solve the problem.
  • Implement your solution in Python.
  • Provide clear comments in your code.
  • Discuss the time and space complexity of your solution.

As always, we’ll share our solution to this problem tomorrow. Stay tuned 😊