Problem · String
Minimum No-Repeat Segments After One Character Removal
Learn this problemProblem statement
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) → intExamples
Example 1
s = "abcccde"return = 1Remove every 'c'. The remaining string is "abde", whose characters are all distinct, so one segment is sufficient.
Example 2
s = "abdaa"return = 1Remove every 'a'. The remaining string is "bd", so the minimum is one segment.
Example 3
s = "aaaa"return = 0Remove every 'a'. The remaining string is empty, so there are no non-empty segments.
Constraints
1 <= s.length <= 2 * 10^5scontains only lowercase English letters.
More Salesforce problems
- Diameter of an Acyclic Undirected GraphONSITE INTERVIEW · Seen Jul 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Maximum Barbell WeightOA · Seen Jul 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)OA · Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026