Sliding Window pattern

Longest Substring Without Repeats

Given a string, find the length of the longest contiguous substring that contains no repeated characters. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 3
  • Medium
  • 3 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Sliding WindowLeetCode 3

Medium

From the first idea to the best one

  1. 01 Brute force · restart on duplicate O(n²)O(charset) space
  2. 02 Better · sliding window with set O(n)O(charset) space
  3. 03 Optimized · jump L via last-seen map O(n)O(charset) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Longest Substring Without Repeats and spot the sliding window pattern in it
  • Brute force · restart on duplicate: O(n²) time, O(charset) space
  • Better · sliding window with set: O(n) time, O(charset) space
  • Optimized · jump L via last-seen map: O(n) time, O(charset) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Sliding Window

See Longest Substring Without Repeats run, step by step

Sign in and this page opens on the animation, with all 8 Sliding Window problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.