All Posts
Leetcode 1750: Minimum Length of String After Deleting Similar Ends
You are given a string s
consisting of only the characters ‘a’, ‘b’, and ‘c’. Your task is to repeatedly perform the following operation any number of times:
- Pick a non-empty prefix from the string where all characters are equal.
- Pick a non-empty suffix from the string where all characters are equal.
- The prefix and suffix should not intersect, and the characters in both should be the same.
- Remove the prefix and suffix.
Your goal is to find the minimum length of the string after performing the operation any number of times.