Minimum Trim Length String

Given a string s that contains only the characters 'a', 'b', and 'c', you may apply the following operation any number of times, including zero times:

  1. Pick a non-empty prefix in which every character is the same.
  2. Pick a non-empty suffix in which every character is the same.
  3. The prefix and the suffix must not overlap.
  4. The character in the prefix and the character in the suffix must be the same.
  5. Delete both the prefix and the suffix.

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

A single remaining character cannot be removed, because removing a prefix and a suffix of the same character would require both ends to contain that character, and they would overlap at the same index. The minimum length is therefore at least 1 unless the whole string is removed.

Examples
Input: "ca"
Output: 2
Hints

Minimum Trim Length String

Given a string `s` that contains only the characters `'a'`, `'b'`, and `'c'`, you may apply the following operation any number of times, including zero times: