Skip to content

Practice Optimal Partition of 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#2405
LeetCode Problem

Optimal Partition of String

Problem Statement

Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition. Note that each character should belong to exactly one substring in a partition.

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

Examples

# Example 1

Input
s = "abacaba"
Output
4

# Example 2

Input
s = "ssssss"
Output
6

Constraints

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

Related LeetCode Problems

Practice more problems similar to Optimal Partition of String.

Review your practice with PhantomCodeAI

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