#3666
Minimum Operations to Equalize Binary String
hard · 45.4% accepted · 300 likes · top 29%
math · string · breadth-first search · union-find · ordered set
Description
You are given a binary string s, and an integer k.
In one operation, you must choose exactly k different indices and flip each '0' to '1' and each '1' to '0'.
Return the minimum number of operations required to make all characters in the string equal to '1'. If it is not possible, return -1.
Solution