← switch

3. Longest Substring Without Repeating Characters

medium

Hash Table · String · Sliding Window

read the problem on leetcode →

first solved 18 Sept 2026

python
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        left = 0
        max_len = 0
        seen = set()

        for right in range(len(s)):
            while s[right] in seen:
                seen.remove(s[left])
                left += 1

            seen.add(s[right])
            max_len = max(max_len, right - left + 1)

        return max_len
Longest Substring Without Repeating Characters · switch