Top 150 InterviewEasy

Longest Substring Without Repeating Characters

Detailed guide and Python implementation for the 'Longest Substring Without Repeating Characters' problem.

Problem Statement

Easy

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

Write a function lengthOfLongestSubstring(s: str) -> int.

Constraints
  • 0 <= len(s) <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces

Examples

Example 1
Input
s = "abcabcbb"
Output
3
Explanation

The answer is "abc", with a length of 3.

Example 2
Input
s = "bbbbb"
Output
1
Explanation

The answer is "b", with a length of 1.

Example 3
Input
s = "pwwkew"
Output
3
Explanation

The answer is "wke", with a length of 3. Note that "pwke" is a subsequence, not a substring.

Need a Hint?
Consider using Sliding Window-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.