Minimum Number of Non-Empty Disjoint Segments
Learn this problemProblem statement
Given a string, find the minimum number of non-empty disjoint segments a string can be partitioned into, such that each segment has no repeated characters. Choose the partitioning that yields the fewest such segments among all possible ways to partition the string.
Note: Each character of the string should be in exactly one segment.
Source correction (July 2, 2026) 𐔌՞ ܸ.ˬ.ܸ՞𐦯 : I updated this page to match the official source image from July 1, 2026. Example 1 now uses s = "abcc", the partition table is included, the old extra visible example that was not in this source was removed, the July 1 sighting date was added, and the official source image is shown below.
Function
minimumDisjointSegments(s: String) → intExamples
Example 1
s = "abcc"return = 2Possible partitions of the string:
| String partition | Number of Segments |
|---|---|
"a", "b", "c", "c" | 4 |
"abc", "c" | 2 |
"ab", "c", "c" | 3 |
It can be concluded that the fewest number of partitioned segments is 2.
Example 2
s = "abdaa"return = 3It can be concluded that the partition "abd", "a", and "a" is the optimal partitioning of s into non-empty disjoint segments, each having no repeating characters.
Constraints
1 <= |s| <= 2 * 10^5- It is guaranteed that the string
sconsists only of lowercase English letters.
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026
- Count Descending SubarraysOA · Seen Apr 2026