Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Non-Overlapping Substrings

med
30 min
Try to solve the Maximum Number of Non-Overlapping Substrings problem.

Statement

Given a string s of lowercase English letters, find the maximum number of non overlapping substrings that meet the following criteria:

  • If a character appears in a chosen substring, all occurrences of that character in s must also be contained within that same substring.

  • No two chosen substrings may overlap.

If there are multiple valid collections of substrings that achieve the maximum possible count, return the one that minimizes the total sum of their lengths. The substrings may be returned in any order.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s contains only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Non-Overlapping Substrings

med
30 min
Try to solve the Maximum Number of Non-Overlapping Substrings problem.

Statement

Given a string s of lowercase English letters, find the maximum number of non overlapping substrings that meet the following criteria:

  • If a character appears in a chosen substring, all occurrences of that character in s must also be contained within that same substring.

  • No two chosen substrings may overlap.

If there are multiple valid collections of substrings that achieve the maximum possible count, return the one that minimizes the total sum of their lengths. The substrings may be returned in any order.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s contains only lowercase English letters.