FastPrepMinimum Number of Non-Empty Disjoint Segments
Problems/Minimum Number of Non-Empty Disjoint Segments

Minimum Number of Non-Empty Disjoint Segments

IBM logoIBM● MediumINTERNFULLTIMENEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

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

Function

minimumDisjointSegments(s: String) → int

Examples

Example 1

s = "abcc"return = 2

Possible partitions of the string:

Possible partitions of the string
String partitionNumber 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 = 3

It 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 s consists only of lowercase English letters.

More IBM Online Assessment questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026
  • Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
  • Maximum Compatible Time WindowsOA · Seen Oct 2026

Similar questions at other companies

  • Maximize Consecutive Dance Moves 🩰TikTok · OATikTok interview questions
  • Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
  • Earn the Most 🐝Capital One · OACapital One interview questions
  • Maximum String OperationsMicrosoft · OAMicrosoft interview questions
  • Perfect SubstringAXQ Capital · OA
  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
  • Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
  • Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
  • Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
  • Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int minimumDisjointSegments(String s) {
      // write your code here
    }

}
Checking account…