Notes

Personal notes on various topics

View on GitHub

Longest Substring Without Repeating Characters

Problem Statement

Given a string s, determine the length of the longest substring that contains no repeating characters.

Examples

Example 1
Input: s = "abcabcbb"
Output: 3
Explanation: The longest substring without repeating characters is "abc", with a length of 3. Other valid substrings include "bca" and "cab".

Example 2
Input: s = "bbbbb"
Output: 1
Explanation: The longest substring without repeating characters is "b", with a length of 1.

Example 3
Input: s = "pwwkew"
Output: 3
Explanation: The longest substring without repeating characters is "wke", with a length of 3. Note that "pwke" is a subsequence, not a substring.

Constraints

Code Template

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        # Write your code here
        pass

Solutions

Back to Problem List Back to Categories