Longest Unique Substring Range
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google flagged this one in August 2026, and the input size does the talking: text can hit 10^6 characters, so checking every substring for duplicates is dead on arrival. This is the longest substring without repeating characters problem, just returning the [start, end] range instead of the length. The report also mentioned a follow-up about input too big for memory. If you're taking this OA soon, you need the window logic cold and the tie-break rule right. StealthCoder is the safety net running invisibly during the live OA if your mind goes blank on the pointer updates.
The problem
You are given a nonempty string text. Return [start, end], the zero-based inclusive indices of a longest contiguous substring whose characters are all distinct. If several longest valid substrings exist, return the one with the smallest start index. Process the string from left to right in O(text.length) time and use O(1) auxiliary space for the fixed printable-ASCII alphabet. What the interview report shared The report described a sliding-window solution and then asked how the approach should change when the input is too large to keep in memory. Function longestUniqueSubstringRange(text: String) → int[] Examples Example 1 text = "abcabcbb" return = [0,2] The maximum length is 3. The valid ranges [0,2], [1,3], [2,4], and [3,5] all have that length, so the earliest range is returned. Example 2 text = "bbbbb" return = [0,0] Every valid substring contains one b. The earliest one begins and ends at index 0. Example 3 text = "pwwkew" return = [2,4] Both wke at [2,4] and kew at [3,5] have maximum length 3. The earlier range is returned. Example 4 text = "dvdf" return = [1,3] After the second d, the window moves forward and the substring vdf becomes the unique maximum. Constraints 1 <= text.length <= 10^6. text contains printable ASCII characters. The returned range uses zero-based inclusive indices. When several ranges have the same maximum length, return the earliest one.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is a sliding window, not real DP, despite the hint. Keep a left pointer and a map from each character to its last seen index. Scan right. If the current character was last seen at or after left, jump left to that index plus one. Then compare the window length to the best so far. Update only when strictly longer. That strict comparison gives you the smallest start index on ties, which is the rule the problem demands. The pitfall is moving left backward. Without the check that the last index is at least left, a stale entry will shrink your window wrongly. Use a 128-slot array for O(1) space. Test on dvdf and pwwkew before submitting. StealthCoder is the hedge if the live OA rattles you and the jump logic slips.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Longest Unique Substring Range 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as longest substring without repeating characters. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Unique Substring Range FAQ
What's the trick to Longest Unique Substring Range?+
Track the last seen index of every character and move the left pointer past a repeat in one jump. You never rescan. Each character is visited once, so the whole thing runs in O(n). Record start and end whenever the window becomes strictly longer than the best.
How do I guarantee the earliest range on ties?+
Only update your best answer when the new window is strictly longer than the current best. Since you scan left to right, earlier windows get recorded first, and equal-length later ones never overwrite them. Using greater-or-equal is the classic bug here.
Is this really dynamic programming?+
Not in practice. The hint says DP, but the clean solution is a sliding window with a last-index table. You can describe it as tracking the best window ending at each position, but you don't need a DP array. Code the window version.
How do I handle the follow-up about input too big for memory?+
Stream the characters in chunks. The state is small: the 128-entry last-index table, the left pointer, the current absolute index, and the best range. You never need the full string stored, only the running counters. Say that clearly and you've answered it.
How do I prepare for this in 48 hours?+
Write the last-index sliding window from scratch twice, once returning length and once returning the range. Run the four examples by hand, especially dvdf. Check a single-character string and an all-unique string. That covers the edge cases this problem actually tests.