Reported August 2024
Highspotsliding window

Longest Substring Without Repeating Characters

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

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

Highspot reportedly put this one in front of candidates in August 2024, and the 10^5 length cap is the whole story. Checking every substring is O(n^2) pairs with a uniqueness check on top, so brute force dies on a long string. The pattern is a sliding window with a hash map of last-seen positions. It's the classic longest substring without repeating characters problem, and it's very learnable in a day or two. If your brain locks up mid-assessment, StealthCoder runs invisibly on your desktop as a safety net while you work through it.

The problem

Given a string s, return the length of its longest contiguous substring that contains no repeated characters.

Function
lengthOfLongestSubstring(s: String) → int

Examples
Example 1
s = "abcabcbb"
return = 3
"abc" is a longest substring without repeated characters, so the answer is 3.
Example 2
s = "bbbbb"
return = 1
Every substring with distinct characters contains at most one b.

Constraints
1 <= s.length <= 10^5.
s contains English letters, digits, and common symbols.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: keep a window [left, right] with all unique characters. Walk right across the string. Store each character's last index in a map. When you see a character whose last index is >= left, jump left to lastIndex + 1. Then update the map and track the max of right - left + 1. That's O(n) time and O(k) space, where k is the character set size. The common pitfall is moving left backward. If the last index of a character is before left, ignore it, so always take the max of left and lastIndex + 1. Another trap is resetting the window or the map on a duplicate, which turns it into O(n^2). Test "abba" by hand, since it breaks the lazy version. The hinted dynamic-programming label is a stretch here. The window is the real solution. If you blank on the live OA, StealthCoder is the hedge that surfaces this pattern while you type.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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 Highspot's OA.

Highspot reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Substring Without Repeating Characters FAQ

How hard is this Highspot OA question really?+

It's a medium on paper but a very common one. The idea is short, and the bugs are in the details. If you've seen sliding windows once, you can write it in ten minutes. Without that, you'll reach for brute force and stall on the 10^5 limit.

What's the trick to get O(n)?+

Keep a hash map from character to its last seen index, plus a left pointer. On a repeat inside the window, move left to lastIndex + 1. Never move left backward. Track the best window length at every step. One pass, no rescans.

Why does brute force fail here?+

The string can reach 10^5 characters. Checking all substrings is O(n^2) starts and ends, and each needs a uniqueness check, which pushes toward O(n^3) if you're sloppy. That's far too slow. The constraint is a hint that a linear pass is expected.

What edge cases should I test before submitting?+

Try "abba", which catches the left pointer moving backward. Try a single character, an all-same string like "bbbbb", and an all-distinct string. Also test symbols and digits, since the input isn't just lowercase letters. Those five cases cover most wrong answers.

How do I prepare for this in 48 hours?+

Write the sliding window solution from scratch twice, once with a set and once with a last-index map. Then do two or three related window problems so the pattern feels natural. Say the invariant out loud: the window always holds unique characters. That's what you need to recall under pressure.

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

OA at Highspot?
Invisible during screen share
Get it