Skip to content

Practice Minimum Length of String After Deleting Similar Ends

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

Medium#1750
LeetCode Problem

Minimum Length of String After Deleting Similar Ends

Problem Statement

Repeatedly choose a nonempty prefix and a nonempty suffix that do not overlap. Each must consist of one repeated character, and that character must be the same at both ends. Remove both selected parts together. Return the minimum remaining length of s after any number of operations, including zero.

Source: Minimum Length of String After Deleting Similar Ends on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "ca"
Output
2

# Example 2

Input
s = "cabaabac"
Output
0

# Example 3

Input
s = "aabccabba"
Output
3

Constraints

1 <= s.length <= 10^5
s only consists of characters 'a', 'b', and 'c'.

Related LeetCode Problems

Practice more problems similar to Minimum Length of String After Deleting Similar Ends.

Review your practice with PhantomCodeAI

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