Tap here to switch tabs
Problem
Submissions

Problem: Minimum Flips to Make Binary String Coherent

Minimum Flips to Make Binary String Coherent asks you to flip characters in a binary string so it contains neither 011 nor 110 as a subsequence, returning the fewest flips needed.

Statement

You are given a binary string s. In a single operation, you can flip any character in s from '$0$' to '$1$' or from '$1$' to '$0$'.

A string is defined as coherent if it does not contain "$011$" or "$110$" as a subsequence.

Return the minimum number of flips required to make s coherent.

Constraints:

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

  • s[i] is either '$0$' or '$1$'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Flips to Make Binary String Coherent

Minimum Flips to Make Binary String Coherent asks you to flip characters in a binary string so it contains neither 011 nor 110 as a subsequence, returning the fewest flips needed.

Statement

You are given a binary string s. In a single operation, you can flip any character in s from '$0$' to '$1$' or from '$1$' to '$0$'.

A string is defined as coherent if it does not contain "$011$" or "$110$" as a subsequence.

Return the minimum number of flips required to make s coherent.

Constraints:

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

  • s[i] is either '$0$' or '$1$'.