Split a String Into the Max Number of Unique Substrings

Given a string s, return the maximum number of unique substrings that the given string can be split into.

You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms the original string. However, you must split the substrings such that all of them are unique.

A substring is a contiguous sequence of characters within a string.

Example 1
Inputs = "ababccc"
Output5
One way to split maximally is ['a', 'b', 'ab', 'c', 'cc']; splitting like ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid as 'a' and 'b' appear multiple times.
Example 2
Inputs = "aba"
Output2
One way to split maximally is ['a', 'ba'].

Constraints

  • 1 <= s.length <= 16
  • s contains only lower case English letters.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate