Reported September 2026
Infosyssliding window

Longest Substring Without Repeating Characters

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

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

A hash map of last-seen indexes is the whole solution to the Infosys OA question reported in September 2026, Longest Substring Without Repeating Characters. You've probably seen it before, which is the danger. Familiar problems make people write code on autopilot and miss the off-by-one in the window logic. The input is a string of printable ASCII, up to 50,000 characters, and you return the length of the longest stretch with no repeats. It's a sliding window problem, even though the hint says dynamic programming. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution in real time.

The problem

You are given a string s consisting of printable ASCII characters.
Return the length of the longest substring of s that contains no repeated character.
The empty string has length 0.

Function
lengthOfLongestSubstring(s: String) → int

Examples
Example 1
s = "abcabcbb"
return = 3
The substring abc has length 3 and no repeated character. Longer windows such as abca repeat a.
Example 2
s = "bbbbb"
return = 1
Every character is b, so the longest non-repeating substring has length 1.

Constraints
0 <= s.length <= 5 * 10^4.
s contains only printable ASCII characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a sliding window with a map from character to its most recent index. Keep a left pointer. Walk the right pointer across the string. When the current character was last seen at an index at or after left, jump left to that index plus one. Then record right minus left plus one as a candidate for the max. The common pitfall is moving left backward. If the stored index is behind left, you must ignore it, so take the max of the two. Another miss is the empty string, which should return 0. With printable ASCII, a 128-slot array works instead of a hash map and runs in O(n) time. A brute force over all substrings is O(n^2) or worse and will likely fail at 50,000 characters. If the pointer logic slips under pressure, StealthCoder is the hedge during the live OA.

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

Infosys 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

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

Use a sliding window with a map of each character's last seen index. When you hit a repeat inside the current window, move the left edge to one past the previous occurrence. Track the best window length as you go. One pass, O(n) time.

Is this really dynamic programming like the hint says?+

Not in the usual sense. You can frame it as the best substring ending at each index, but the clean solution is a sliding window with a hash map or a fixed 128-size array. Write it as a window and you'll be faster and less error-prone.

What edge cases should I test before submitting?+

Test the empty string, which returns 0. Test a single character, all identical characters like bbbbb, and a string with no repeats. Also test a repeat that sits behind the left pointer, like abba. That case breaks solutions that don't take the max when moving left.

Will brute force pass with a length of 50,000?+

Probably not. Checking every substring is at least O(n^2), and with a set per check it climbs toward O(n^3). At 50,000 characters that's billions of operations. The single-pass window is O(n) and is what the constraints are pushing you toward.

How do I prepare for this in 48 hours?+

Write the sliding window version from scratch twice without looking. Then do it with a 128-length array instead of a map. Trace abba by hand to confirm your left pointer never moves backward. That covers nearly every variation of this problem.

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

OA at Infosys?
Invisible during screen share
Get it