Skip to contentKEEP THE CRAFTTHE SANCTUARY

Maximum Unique String Split

Cut a string into as many pieces as possible while keeping every piece different.

The problem

Implement Solution.maxUniqueSplit(text). Cut text into consecutive non-empty pieces that together spell text, so that no two pieces are the same string. Return the largest number of pieces you can get. For example, "ababccc" can be cut into ["a", "b", "ab", "c", "cc"], which gives 5. Pieces may be longer than one letter; only whole pieces have to differ. Constraints: text has 1 to 16 lowercase English letters.

Starter code

class Solution:
    def maxUniqueSplit(self, text):
        pass

Public examples

  1. text = "ababccc"gives5
  2. text = "ab"gives2
  3. text = "aa"gives1

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.