#1593
Split a String Into the Max Number of Unique Substrings
pupil · 580 · lc medium +29 · verified · 68.6% accepted · 1,513 likes · top 76%
Description
Given a string s, split it into the maximum number of non-empty substrings such that all substrings are distinct from one another. Return that maximum count.
Example 1:
Input: s = "ababccc"
Output: 5
Explanation: One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']. Splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as you have 'a' and 'b' multiple times.
Example 2:
Input: s = "aba"
Output: 2
Explanation: One way to split maximally is ['a', 'ba'].
Example 3:
Input: s = "aa"
Output: 1
Explanation: It is impossible to split the string any further.
Code
1
2
3