Reported September 2026
Capgeminisliding window

Longest Substring Without Repeating Characters

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

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

Capgemini reported this one in September 2026, and it's a classic: find the longest substring with no repeated characters. Strip the wording and it's a window that grows to the right and only shrinks when a duplicate shows up. That's sliding window, not real dynamic programming, even though the tag says otherwise. If you've got an OA invite and 48 hours, this is a pattern you can lock in tonight. StealthCoder sits invisibly on your screen during the live OA as a safety net if your mind goes blank on the pointer logic.

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 left pointer and a map from character to its last seen index. Walk the right pointer across the string. When the current character was seen at an index at or after left, jump left to that index plus one. Update the best length as right minus left plus one. That's O(n) time and O(k) space for k distinct characters. The common pitfall is moving left backward. If the stored index is behind left, ignore it, so use max(left, last+1). Another miss is rebuilding a set for every start, which is O(n^2) and risky at 10^5 length. Test on "abba" because it breaks the naive jump. If you freeze during the live OA, StealthCoder is the hedge that reads the problem and hands you the window logic.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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

Capgemini 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 Substring Without Repeating Characters FAQ

What's the trick for Longest Substring Without Repeating Characters?+

Use a sliding window with a hash map of last seen indexes. Move the right pointer one step at a time. On a repeat inside the window, push the left pointer past the earlier occurrence. Track the max window size as you go. One pass, linear time.

Is this really dynamic programming?+

The hint says dynamic programming, and you can frame it as the best substring ending at each index. But the clean solution is a sliding window with two pointers. It's simpler to code, easier to debug under pressure, and hits the same O(n) time.

Why does "abba" break so many solutions?+

When you hit the second a, its last seen index is 0, but left has already moved to 2 because of the repeated b. If you set left to 1 you shrink backward and get a wrong answer. Always take the max of left and last seen plus one.

Will brute force pass with s.length up to 10^5?+

No. Checking every substring is O(n^2) or worse, and 10^5 squared is far too slow. You need the linear sliding window. Mention the complexity in a comment so it's clear you picked the right approach on purpose.

How do I prepare for this in 48 hours?+

Code the map-based window from scratch twice without looking. Run it on abcabcbb, bbbbb, abba, and a single character. Then write the set-based version with a while loop to shrink. Knowing both means you can recover if one slips your mind.

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

OA at Capgemini?
Invisible during screen share
Get it