Longest Substring Without Repeating Characters

Medium · Arrays & Strings · about 20 minutes

Asked at Amazon, Apple, Bloomberg, ByteDance, Microsoft, Pinterest, Snap, X (Twitter), Etsy, Zillow, Discord, Duolingo, Riot Games, Match Group, Twitch.

Scan a string and report how long its longest stretch of consecutive characters is when no character in that stretch shows up twice.

Example: in "abcabcbb" the best stretch is "abc", so the answer is 3.

Related guides