Reported September 2026
Salesforcestring

Minimum Unique-Character Segments After Deletion

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 reportedly put this one in front of candidates in September 2026, and the input size is the first thing that matters. The string runs up to 200,000 characters, so anything quadratic is dead on arrival. The problem looks like a string partition, but the real shape is small: only 26 letters can be removed. If you've got an OA coming, this is a greedy scan wrapped in a 26-way loop. StealthCoder sits invisibly on your screen as a safety net if you blank on the structure mid-assessment, but the idea is simple enough to hold in your head.

The problem

You are given a string s containing only lowercase English letters.
Perform exactly one deletion operation:
Choose any lowercase English letter removed. The chosen letter does not need to appear in s.
Delete every occurrence of removed from s.
After the deletion, partition the remaining string into the minimum possible number of contiguous, nonempty segments such that no letter appears more than once inside any segment.
Return the minimum segment count obtainable over all choices of removed. If the deletion leaves an empty string, return 0.

Function
minSegmentsAfterDeletion(s: String) → int

Examples
Example 1
s = "abac"
return = 1
Choose 'a'. Removing every 'a' leaves "bc", whose letters are distinct, so one segment is enough.
Example 2
s = "abacbc"
return = 2
Deleting 'a' leaves "bcbc", which can be partitioned as "bc" | "bc". Deleting 'c' similarly leaves "abab". No deletion choice makes every remaining letter distinct, so the answer is 2.
Example 3
s = "aaaa"
return = 0
Choose 'a'. Every character is deleted, so the remaining empty string needs zero nonempty segments.

Constraints
1 <= s.length <= 2 * 10^5.
s contains only lowercase English letters.
The deletion operation chooses one of the 26 lowercase English letters and removes all of its occurrences.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's the trick. There are only 26 possible letters to delete, so try each one. For each choice, build the filtered string by skipping that letter, then greedily cut segments. Keep a set (or a 26-slot array) of letters seen in the current segment. When the next character is already in the set, start a new segment and reset. Greedy is optimal because extending a segment as far as possible never hurts. Total work is 26 times n, about 5.2 million steps, which is fine. The pitfalls: forgetting that a letter not in s is a legal choice, and mishandling the empty result, which returns 0. Also don't physically rebuild strings with repeated concatenation. Just skip characters inline. If the greedy reasoning slips under pressure, StealthCoder can hand you the loop structure live, but you'll likely write it faster than you expect.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Minimum Unique-Character Segments After Deletion 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Unique-Character Segments After Deletion FAQ

What's the trick in Minimum Unique-Character Segments After Deletion?+

Only 26 letters can be removed, so brute-force over the choice of letter. For each one, run a greedy single pass that starts a new segment whenever a character repeats inside the current one. Take the minimum count across all 26 options.

What's the time complexity and does it pass the constraints?+

It's O(26 * n), roughly 5.2 million operations for n at 200,000. That passes comfortably. A solution that tries deleting subsets of characters or re-partitions with DP per choice is what you want to avoid.

Why is greedy correct for the segmenting step?+

Any valid segment can be extended until the next character would duplicate one already inside it. Cutting earlier never reduces the count, because a shorter segment leaves more characters for later segments. So cutting only at forced duplicates gives the minimum.

What edge cases should I test before submitting?+

Test a string of one repeated letter, like aaaa, which must return 0. Test a string already all distinct, which returns 1. Test a deletion letter that doesn't appear in s. Also check the examples abac and abacbc, answers 1 and 2.

How do I prepare for this in 48 hours?+

Practice the sliding set pattern: scan, track seen letters, reset on repeat. Then wrap it in a loop over 'a' to 'z' with a skip condition. Write it once from scratch in your language, run the three examples, and you're set.

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