Skip to contentKEEP THE CRAFTTHE SANCTUARY

Longest Substring Without Repeating Characters

Find the length of the longest contiguous part of a string with no repeated character.

The problem

Implement Solution.lengthOfLongestSubstring(text). Return the length of the longest substring of text, a contiguous run of characters, in which no character appears twice. text may contain letters, digits, spaces and symbols, and may be empty, in which case return 0. For example, 'abcabcbb' returns 3 for 'abc'.

Starter code

class Solution:
    def lengthOfLongestSubstring(self, text: str) -> int:
        pass

Public examples

  1. text = "abcabcbb"gives3
  2. text = "bbbbb"gives1
  3. text = "a b!a"gives4

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.