Tap here to switch tabs
Problem
Submissions

Problem: Partition String

Partition String builds a list of unique segments by scanning left to right. Add each character to the current segment; record and reset it when new, or keep extending it when already recorded.

Statement

Given a string s, partition it into a sequence of unique segments using a greedy approach by processing each character from left to right:

  • Maintain a current segment, initially empty, and a list of recorded segments.

  • For each character in s, append it to the current segment.

  • If the current segment has not been seen before, append it to the list of recorded segments and reset the current segment to an empty string.

  • If the current segment has already been seen, keep it and proceed to the next character.

Return the list of unique segments generated by this process.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s contains only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Partition String

Partition String builds a list of unique segments by scanning left to right. Add each character to the current segment; record and reset it when new, or keep extending it when already recorded.

Statement

Given a string s, partition it into a sequence of unique segments using a greedy approach by processing each character from left to right:

  • Maintain a current segment, initially empty, and a list of recorded segments.

  • For each character in s, append it to the current segment.

  • If the current segment has not been seen before, append it to the list of recorded segments and reset the current segment to an empty string.

  • If the current segment has already been seen, keep it and proceed to the next character.

Return the list of unique segments generated by this process.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s contains only lowercase English letters.