Partition String

Given a string s, partition it into unique segments according to the following procedure:

  • Start building a segment beginning at index 0.
  • Continue extending the current segment character by character until the current segment has not been seen before.
  • Once the segment is unique, add it to your list of segments, mark it as seen, and begin a new segment from the next index.
  • Repeat until you reach the end of s.

Return an array of strings segments, where segments[i] is the i^th segment created.

Example 1
Inputs = "abbccccd"
Output["a","b","bc","c","cc","d"]
Following the procedure creates the unique segments "a", "b", "bc", "c", "cc", and "d".
Example 2
Inputs = "aaaa"
Output["a","aa"]
Following the procedure creates the unique segments "a" and "aa"; the final trailing "a" has already been seen and is not added as a new segment.

Constraints

  • 1 <= s.length <= 10^5
  • s contains only lowercase English letters.

Asked at 1 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