Tap here to switch tabs
Problem
Submissions

Problem: Minimum Length of String After Deleting Similar Ends

med
30 min
Try to solve the Minimum Length of String After Deleting Similar Ends problem.

Statement

Given a string s consisting only of characters 'a', 'b', and 'c'.

You can apply the following operation on the string any number of times:
11. Select a non empty prefix where all characters are identical.
22. Select a non empty suffix where all characters are identical.
33. Ensure that the prefix and suffix do not overlap at any index.
44. Ensure that the character in the prefix matches the character in the suffix.
55. Delete both the selected prefix and suffix from s.

Return the minimum possible length of s after applying this operation any number of times.

Constraints:

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

  • s only consists of characters 'a', 'b', and 'c'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Length of String After Deleting Similar Ends

med
30 min
Try to solve the Minimum Length of String After Deleting Similar Ends problem.

Statement

Given a string s consisting only of characters 'a', 'b', and 'c'.

You can apply the following operation on the string any number of times:
11. Select a non empty prefix where all characters are identical.
22. Select a non empty suffix where all characters are identical.
33. Ensure that the prefix and suffix do not overlap at any index.
44. Ensure that the character in the prefix matches the character in the suffix.
55. Delete both the selected prefix and suffix from s.

Return the minimum possible length of s after applying this operation any number of times.

Constraints:

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

  • s only consists of characters 'a', 'b', and 'c'.