Reported September 2026
Amazonsliding window

Longest Substring Without Repeating Characters

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon reported this one in September 2026, and it's the classic longest substring without repeating characters. The hinted tag says dynamic programming, but don't buy it. It reduces to a window that only ever moves forward, and you track the last place each character showed up. If you've got an OA invite and 48 hours, this is the pattern to lock in. It's short, it's common, and the bugs are small but fatal. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you can know this cold before then.

The problem

Given a string s, return the length of the longest contiguous substring whose characters are all distinct.

Function
lengthOfLongestSubstring(s: String) → int

Examples
Example 1
s = "abcabcbb"
return = 3
abc is a longest substring with no repeated character.
Example 2
s = "bbbbb"
return = 1
Every distinct-character substring contains at most one b.
Example 3
s = ""
return = 0
The empty string has no nonempty substring.

Constraints
0 <= s.length <= 200000.
s contains printable ASCII characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a sliding window with a hash map from character to its last seen index. Keep a left pointer. Walk right across the string. When the current character was seen at an index at or after left, jump left to that index plus one. Then update the map and record right minus left plus 1 as a candidate answer. That's O(n) time with O(1) extra space, since the alphabet is printable ASCII. The common pitfall is moving left backward. If the stored index is older than left, you must ignore it, so use max or check the bound. Another miss is the empty string, which should return 0 and falls out naturally. With n up to 200000, brute force over all substrings will time out. If you freeze during the live OA, StealthCoder can surface this window logic fast, but writing it yourself once is better.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Longest Substring Without Repeating Characters cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as longest substring without repeating characters. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Substring Without Repeating Characters FAQ

What's the actual trick in this Amazon OA question?+

Use a sliding window and a map of each character's last index. When you hit a repeat inside the window, move the left edge to just past the old index. Track the max window length as you go. It's one pass, no nested loops.

Is this really dynamic programming like the tag says?+

Not in any way you need to code. You can frame it as DP where the best substring ending at each index depends on the previous one, but the sliding window is the clean solution. Write the window version and skip the DP table.

What edge cases should I test before submitting?+

Test the empty string (return 0), a string of all the same character like bbbbb (return 1), and a string with no repeats at all. Also test a repeat that sits before the left pointer, like abba, since that catches the missing max bug.

Will brute force pass with a 200000-length string?+

No. Checking every substring is at least O(n^2), and often O(n^3) if you re-scan for duplicates. At 200000 characters that's far too slow. You need the O(n) single pass with the last-seen map or a set-based window.

How do I prepare for this in 48 hours?+

Write the last-seen-index solution from memory three times, then do it again with a set and a while loop shrinking the window. Trace abcabcbb and abba by hand. Once both versions feel automatic, move on to similar window problems rather than rereading this one.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it