Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make All Characters Equal

Try to solve the Minimum Cost to Make All Characters Equal problem.

Statement

You are given a 00 indexed binary string s of length n.

You can perform two types of operations on s any number of times:

  • Invert the prefix of s from index 00 to index i with a cost of i +1+ 1.

  • Invert the suffix of s from index i to index n −- 11 with a cost of n −- i.

Inverting a substring means toggling every character in that range, changing '0' to '1' and '1' to '0'.

Return the minimum total cost to make all characters in s equal.

Constraints:

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

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Make All Characters Equal

Try to solve the Minimum Cost to Make All Characters Equal problem.

Statement

You are given a 00 indexed binary string s of length n.

You can perform two types of operations on s any number of times:

  • Invert the prefix of s from index 00 to index i with a cost of i +1+ 1.

  • Invert the suffix of s from index i to index n −- 11 with a cost of n −- i.

Inverting a substring means toggling every character in that range, changing '0' to '1' and '1' to '0'.

Return the minimum total cost to make all characters in s equal.

Constraints:

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

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