Problem · String

Minimum Remaining Length

Learn this problem
MediumWells FargoOA

Problem statement

You are given a string seq made up only of the characters 'A' and 'B'.

You may repeatedly perform the following operation:

  • Delete any occurrence of the substring "AB" or "BB".
  • After deletion, the remaining parts of the string are concatenated.

Your task is to determine the minimum possible length of the string after performing any number of valid deletions.

Note: A substring refers to a contiguous sequence of characters.

Return the minimum remaining length.

Function

getMinimumRemainingLength(seq: String) → int

Examples

Example 1

seq = "BABBA"return = 1

More Wells Fargo problems

drafts saved locally
public int getMinimumRemainingLength(String seq) {
  // write your code here
}
seq"BABBA"
expected1
checking account