2696. Minimum String Length After Removing Substrings - Explanation

Problem Link

Description

Starting with the uppercase string s, repeatedly delete any adjacent AB or CD. The characters on either side join together after a deletion, which may allow more deletions. Return the shortest length you can obtain, including zero if everything can be removed.

Example 1:

Input: s = "A"

Output: 1

Explanation: A single "A" contains neither "AB" nor "CD", so it cannot be removed.

Example 2:

Input: s = "B"

Output: 1

Explanation: A single "B" contains neither removable pair, so its length stays 1.

Example 3:

Input: s = "AB"

Output: 0

Explanation: Remove the pair "AB" in one operation. The remaining string is empty.

Constraints:

  • 1 <= s.length <= 100
  • Only uppercase English letters occur.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.