Reported July 2025
Ciscosliding window

Longest Non-Repeating Substring

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

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

The mistake that sinks a first attempt on this Cisco OA, reported in July 2025, is returning the length instead of the substring, or breaking the tie rule. The task is the classic longest substring without repeating characters, but you return the actual string, and on ties you take the smallest starting index. With s up to 200000 characters, brute force dies. The pattern is a sliding window with a last-seen index map. If you blank mid-assessment, StealthCoder runs invisibly on your screen and can hand you the window logic in real time.

The problem

Given a string s, return a longest contiguous substring that contains no repeated characters.
For this exercise, assume that when several longest valid substrings exist, you must return the one with the smallest starting index. If s is empty, return the empty string.

Function
longestUniqueSubstring(s: String) → String

Examples
Example 1
s = "abcabcbb"
return = "abc"
The longest valid substrings have length 3. The earliest one is "abc", which starts at index 0.
Example 2
s = "pwwkew"
return = "wke"
Both "wke" and "kew" have length 3. The leftmost tie rule selects "wke".
Example 3
s = "bbbbb"
return = "b"
Every valid substring has length 1, so the first character is returned.
Example 4
s = ""
return = ""
The empty string has no non-empty substring, so return "".

Constraints
0 <= s.length <= 200000
s contains lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a two-pointer sliding window. Keep a left pointer and a map (or a 26-slot array, since input is lowercase letters) of each character's last seen index. Walk right across the string. If the current character was seen at an index >= left, jump left to that index + 1. Then check the window length. Update the best answer only when the new length is strictly greater than the best. That strict comparison is what enforces the leftmost tie rule, since earlier windows win equal-length ties. Common pitfalls: using >= and returning a later window on ties, moving left backward when the stored index is stale, and rebuilding substrings inside the loop, which costs extra time. Store only bestStart and bestLen, then slice once at the end. Handle the empty string up front. If you freeze during the live OA, StealthCoder is the safety net that shows the pointer-jump logic so you can type it out cleanly.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Longest Non-Repeating Substring 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

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

Cisco reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Non-Repeating Substring FAQ

What's the trick for Cisco's longest non-repeating substring question?+

Use a sliding window with a last-seen index array. When you hit a repeated character inside the window, move the left pointer to one past its previous index. One pass, O(n) time. Track the best start and length, then slice the string once at the end.

How do I get the tie-breaking rule right?+

Update your best answer only when the current window length is strictly greater than the best length. Since you scan left to right, the earliest window of a given max length gets recorded first and never gets replaced by an equal-length later one. Using >= is the classic bug.

Is this really a dynamic programming problem?+

It's tagged that way sometimes, but the practical solution is a sliding window. You can frame it as DP where the best substring ending at each index depends on the previous one, but you don't need a table. Two pointers and a last-seen map is cleaner and faster to write.

Will a brute force solution pass with length 200000?+

No. Checking every substring is O(n^2) or worse, which is far too slow at 200000 characters. You need the O(n) window approach. Since the alphabet is only lowercase letters, a fixed 26-element array also keeps memory tiny and lookups fast.

How do I prepare for this in 48 hours?+

Write the sliding window version from scratch twice, once returning length and once returning the substring with the tie rule. Test on abcabcbb, pwwkew, bbbbb, and an empty string. Also test a case like abba to catch stale left-pointer bugs. That covers nearly everything this problem can throw at you.

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

OA at Cisco?
Invisible during screen share
Get it