bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 3. Longest Substring Without Repeating Characters

3. Longest Substring Without Repeating Characters

Leetcode Solutions

Sliding Window Optimized

  1. Initialize a hashmap to store character indices.
  2. Initialize two pointers, start and max_length, to 0.
  3. Iterate over the string with an index i.
  4. If the character at index i is in the hashmap and its stored index is greater than or equal to start, update start to the stored index + 1.
  5. Update the hashmap with the current character and its index i.
  6. Update max_length to the maximum of max_length and i - start + 1.
  7. Return max_length after the iteration.
UML Thumbnail

Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...