Skip to content

Practice Partition String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3597
LeetCode Problem

Partition String

Problem Statement

Scan s from left to right while maintaining the set of previously emitted segments. Grow a current segment one character at a time; as soon as its string has not been emitted before, append it to the output, mark it as seen, and start a new segment at the next character. Return the emitted segments in order. If the input ends with a still-seen partial segment, do not emit that remainder; for example, aaaa produces [a, aa].

Source: Partition String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abbccccd"
Output
["a","b","bc","c","cc","d"]

# Example 2

Input
s = "aaaa"
Output
["a","aa"]

Constraints

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

Related LeetCode Problems

Practice more problems similar to Partition String .

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.