Open In App

Maximize partitions such that no two substrings have any common character

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Given string s of size n, the task is to print the number of substrings formed after maximum possible partitions such that no two substrings have a common character.

Examples: 

Input : s = "ababcbacadefegdehijhklij" 
Output :
Explanation: Partitioning at the index 8 and at 15 produces three substrings "ababcbaca", "defegde" and "hijhklij" such that none of them have a common character. So, the maximum partitions are 3.

Input: s = "aaa" 
Output:
Explanation: Since, the string consists of a single character, no partition can be performed. 

We have discussed three different approaches to solve this problem in Maximize String Partitions with No Common Characters


Next Article
Article Tags :
Practice Tags :

Similar Reads