Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Equalize Binary String

Minimum Operations to Equalize Binary String asks you to flip exactly k distinct positions per operation until every character is one, returning the minimum count or -1 if impossible.

Statement

You are given a binary string s and an integer k.

In one operation, you can choose exactly k distinct indices in s and flip the character at each chosen index, changing '0' to '1' and '1' to '0'.

Return the minimum number of operations required to make every character in s equal to '1', or −1-1 if it is impossible.

Constraints:

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

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

  • 1≤1 \leq k ≤\leq s.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Equalize Binary String

Minimum Operations to Equalize Binary String asks you to flip exactly k distinct positions per operation until every character is one, returning the minimum count or -1 if impossible.

Statement

You are given a binary string s and an integer k.

In one operation, you can choose exactly k distinct indices in s and flip the character at each chosen index, changing '0' to '1' and '1' to '0'.

Return the minimum number of operations required to make every character in s equal to '1', or −1-1 if it is impossible.

Constraints:

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

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

  • 1≤1 \leq k ≤\leq s.length