FastPrepMinimum Binary String Length After Pair Removals

Minimum Binary String Length After Pair Removals

Pinecone logoPinecone● EasyFULLTIMEOA
Learn

Problem statement

Given a binary string s, you may repeatedly remove any adjacent pair equal to 01 or 10.

Return the minimum possible length of the remaining string.

Function

minimumRemainingLength(s: String) → int

Examples

Example 1

s = "0101"return = 0

Remove the first 01, then remove the remaining 01.

Example 2

s = "11100"return = 1

Two opposite-bit pairs can be removed, leaving one 1.

Constraints

  • 0 <= s.length <= 100000.
  • Every character of s is 0 or 1.

More Pinecone problems

See Pinecone hiring insights
public int minimumRemainingLength(String s) {
    // Write your code here.
}
s"0101"
expected0
Checking account…