Reported September 2024
Salesforcesliding window

Longest Substring

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

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

Salesforce's September OA included a Longest Substring problem, and it's the kind of question that looks simple until you hit edge cases at scale. You're being tested on whether you know the sliding-window or dynamic-programming approach cold, and whether you can handle overlapping constraints without overthinking it. This is exactly where StealthCoder becomes your safety net if you blank on the pattern during the live OA.

Pattern and pitfall

The core trick here is recognizing that a brute-force nested loop (checking every substring) times out. Instead, you need either a sliding window to track the longest valid substring in one pass, or dynamic programming to build up state as you scan left to right. The pitfall candidates hit most: they code the window expansion correctly but mess up the contraction logic, or they forget to track the max length as they go. DP variants often require you to define state carefully (is this the longest ending at index i, or the longest found so far?). StealthCoder's job is to catch which pattern the problem actually wants and feed you the state transitions before you lock in your approach.

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

Salesforce 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 FAQ

Is this the 'no duplicate characters' variant or a different constraint?+

Salesforce hasn't always specified the exact constraint. It could be no repeating characters, at most k distinct characters, or a substring matching some condition. Read the problem text carefully on the day. If it's no repeats, sliding window with a hash set is your move.

Should I use a hash map or a set?+

Use a hash map if you need to track character positions (to know how far back to slide). Use a set if you only care whether a character has appeared. For longest substring problems, the map is usually safer because it lets you jump your left pointer directly.

How do I know when to use DP instead of sliding window?+

Sliding window works when the constraint is local (like 'no repeats in this window'). DP is needed if the constraint depends on non-contiguous subproblems or you're optimizing over all substrings. Salesforce usually prefers the simpler pattern, but read the constraint first.

What's the time complexity I need to hit?+

Linear or O(n log n) is expected. If your solution is O(n^2) or worse, you're in brute-force territory. Sliding window is O(n) time and O(min(n, charset size)) space. That's the target.

Will there be a follow-up about returning the actual substring, not just the length?+

Possibly. Track the start and end indices of the longest substring as you go, not just the length. That way you can reconstruct it in O(1) extra time when asked.

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

OA at Salesforce?
Invisible during screen share
Get it