Maximum Unique Substring Split
Problem statement
Split the entire string s into nonempty contiguous substrings such that no two chosen substrings have the same value. Return the maximum possible number of substrings.
Keep characters in their original order and use every character exactly once. Only the maximum count is returned; different optimal partitions are equally valid.
Function
maxUniqueSplit(s: String) → intExamples
Example 1
s = "abca"return = 3One optimal partition is ["a","b","ca"], with three distinct pieces. Four pieces would repeat "a", so the maximum is 3.
Example 2
s = "aaaa"return = 2Use ["a","aaa"] or ["aaa","a"]. Three distinct positive substring lengths would need at least six characters, so the maximum is 2.
Constraints
1 <= s.length <= 16- Every character of s is a lowercase English letter.