Skip to content

Practice Minimize String Length

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

Easy#2716
LeetCode Problem

Minimize String Length

Problem Statement

Choose any character position in s and delete either the closest equal character to its left or the closest equal character to its right, when that occurrence exists. Repeat either operation as often as desired. Return the smallest remaining string length.

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

Examples

# Example 1

Input
s = "aaabc"
Output
3

# Example 2

Input
s = "cbbd"
Output
3

# Example 3

Input
s = "baadccab"
Output
4

Constraints

1 <= s.length <= 100
s contains only lowercase English letters

Related LeetCode Problems

Practice more problems similar to Minimize String Length.

Review your practice with PhantomCodeAI

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