Longest Substring Without Repeats
Step by Step
Sliding window grows to the right. When a letter repeats, the left edge jumps just past its last copy and never moves back.
Step through every window move in both directions, then share a link to the step where the left edge jumped.
What You Watch While the Window Slides
The window, the last seen letters and the length change on every step.
Every letter inside the window must be unique. Repeats push the left edge forward and never backward.
CodeStory's visualiser shows the window growing and shrinking with the length so far inside it. Marked code lines follow every move, and you can step back, step forward or play.
Open abba first. Then load dvdf to see the left edge jump past the first d.
How the Longest Substring Window Moves
Steps below follow the window on your screen.
- 1Take in the letter on the right.
- 2Check where that letter last appeared.
- 3Jump the left edge just past that copy when it sits inside the window.
- 4Record the longest window seen so far.
Window Mistakes the Visualiser Shows
A switch in the visualiser turns the mistake on, so you can watch the state go wrong.
- Bug: window never shrinksNotices the repeat but never moves left, so the window keeps a duplicate and the length keeps counting. Load abba to see it.
- Bug: left moves backDrops the "last[c] >= left" check, so an old copy outside the window drags left backwards. Load abba or tmmzuxt to see it.
Longest Substring Inputs Worth Trying
Six presets cover repeats, old copies and a window that never shrinks.
- abbaSecond a already sits outside the window. Switch on both bugs here.
- One letter repeatedleft jumps on every letter, so the answer is 1.
- No repeatsWindow never shrinks, so both bugs get this one right.
- Answer in the middleAnswer "wke" starts after the double w.
- dvdfleft jumps to 1, just past the first d, not all the way to 2, so the answer is "vdf".
- Old copy far behindAt the last t, the first t is long gone. Switch on "Bug: left moves back" here.
Longest Substring Cost in Time and Space
Both edges move forward only, so the work stays linear.
- Time
- O(n)counted from the window moves you step through
- Space
- O(k)a table of last seen letters
- Pattern
- Sliding windowGrow the right edge, shrink the left and never look back.
Practise Sliding Window Beyond Substrings
Watching shows the window and solving trains you to spot when a window fits.
Everything in the App in One Place
Practice, interviews and tools all start free. Swipe to see the rest.
DSA practice
Problems filed under the pattern that solves them, not a sheet.
352 problemsOpenCompany sets
Practise what one company asks in the week before your round.
463 companiesOpenCoding interview
Choose a role, write in a real editor and answer while you type.
scored reportOpenMock interviews, spoken
You answer out loud and CodeStory follows up on what you said.
32 topicsOpenDatabase round
Answer DBMS the way a panel asks it, with indexes, joins and normal forms.
in Core CSOpenOOP round
Inheritance, polymorphism and the follow-up you never rehearse.
in Core CSOpenSystem design
How real systems are built, from the primitives to the AI stack.
27 chaptersOpenSQL practice
Real schemas, your query, the rows it returns and a clear verdict.
39 questionsOpenAptitude
Quant, logical, verbal, DI and technical, timed like the real test.
280 questionsOpenOnline assessment
Get a clock, marks per question and hidden tests like a company's judge.
37 papersOpenAlgorithm visualiser
Watch it play on your own input, one step at a time.
26 algorithmsOpenAI that helps, not solves
Hints one at a time and AI review before a mentor sees your work.
100 free creditsOpenResume builder
Build it inside the app, next to the work you practised.
in the appOpenProgress and readiness
One score and the axis where you are weakest.
tracked dailyOpen
Sign up for 100 AI credits now and get 100 more every month. Start free in the app
Longest Substring Visualiser FAQs
Open the visualiser and follow the window letter by letter.
Open the visualiserWhat does the longest substring without repeats visualiser show?
CodeStory's visualiser shows the window growing and shrinking with the length so far inside it, beside the highlighted code. Move back and forth through every step, or let it play.
What is the time complexity of the longest substring without repeats?
O(n) time and O(k) space. Live counts show both edges moving forward only.
Why does my longest substring code fail on some inputs?
Two traps cause most failures. Switch either bug on in the visualiser and watch the window keep a duplicate or the left edge move backwards.
Can I use my own input?
Yes. Enter your own input and the visualiser plays the algorithm on it, including the edge cases that break a solution in an interview.
Is the visualiser free?
Yes. Every new account starts with 100 AI credits and gets 100 more monthly, while watching an algorithm costs nothing.
Stuck on Sliding Window? Get a Free Callback
Tell CodeStory which sliding window step loses you, and a mentor plans what comes next.
- 1CodeStory checks your level, from sliding window basics to interview ready.
- 2CodeStory explains online and campus batches, with timings for your weekdays or weekends.
- 3You decide. No pressure, no payment on the call.