Reported July 2025
Salesforcestring

Minimum No-Repeat Segments After One Character Removal

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 reported this one in July 2025, and the input size is the whole story. With s up to 2 * 10^5, you can't just try every character, rebuild the string, and rescan it for every case in a sloppy way. Well, you can try 26 characters, but only if each pass is linear. The problem is string work with a greedy segment count. Remove one letter everywhere, then split what's left into the fewest pieces with no repeated character inside any piece. If you blank on the greedy part, StealthCoder is the safety net running invisibly during the live OA.

The problem

Given a lowercase English string s, choose exactly one lowercase English character and remove every occurrence of that character from s.
Partition the remaining string into the minimum number of non-empty, disjoint, contiguous segments such that no segment contains a repeated character. Return that minimum number of segments.
If removing the chosen character makes the string empty, return 0.

Function
getNoRepeatSegments(s: String) → int

Examples
Example 1
s = "abcccde"
return = 1
Remove every 'c'. The remaining string is "abde", whose characters are all distinct, so one segment is sufficient.
Example 2
s = "abdaa"
return = 1
Remove every 'a'. The remaining string is "bd", so the minimum is one segment.
Example 3
s = "aaaa"
return = 0
Remove every 'a'. The remaining string is empty, so there are no non-empty segments.

Constraints
1 <= s.length <= 2 * 10^5
s contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there are only 26 candidate characters. For each one, build the filtered string in O(n), then count segments greedily. Walk left to right, keep a set (or a 26-slot boolean array) of letters in the current segment. When the next character is already in the set, start a new segment, clear the set, and add that character. Greedy works because extending a segment as far as possible never hurts. Take the minimum across all 26 choices. Total cost is about 26 * n, which is fine for 2 * 10^5. Pitfalls: forgetting the empty-string case that returns 0, and clearing the set in O(26) too often. Also, only try letters that exist in s, or at least handle absent letters cleanly, since removing nothing is a valid-looking choice but may not be allowed. If you freeze on the greedy reset logic mid-assessment, StealthCoder can hand you the clean loop.

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 Minimum No-Repeat Segments After One Character Removal 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

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

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

Minimum No-Repeat Segments After One Character Removal FAQ

What's the trick to this Salesforce problem?+

Only 26 letters exist, so try each one as the removed character. For each, filter the string and greedily count segments, starting a new one whenever a repeat appears. Take the minimum. That's O(26 * n), which easily handles n up to 2 * 10^5.

Why does greedy segmentation give the minimum?+

Extending a segment until the next character would repeat never makes things worse. Any valid partition can be shifted so each cut moves as far right as possible without increasing the count. So cutting only at forced repeats gives the fewest segments.

What edge cases should I test?+

Test a string where all characters are the same, like aaaa, which must return 0. Test a single character string. Test a string with no repeats after removal, which returns 1. Also test strings where removing a letter merges neighbors that were equal, since that creates new repeats.

Can I skip trying all 26 characters?+

Not safely. The best letter to remove isn't obvious, because removing a frequent letter can both shrink the string and eliminate repeats, but sometimes a rarer one wins. Brute force over 26 is cheap, so just do it and keep the minimum.

How do I prepare for this in 48 hours?+

Write the greedy distinct-segment counter from scratch until it's automatic, using a 26-size boolean array. Then wrap it in a loop over letters. Practice the empty-result case. This is a short pattern, so one clean solo run plus edge-case tests is enough prep.

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