2712. Minimum Cost to Make All Characters Equal
You are given a 0-indexed binary string
s
of lengthn
on which you can apply two types of operations:
- Choose an index
i
and invert all characters from index0
to indexi
(both inclusive), with a cost ofi + 1
- Choose an index
i
and invert all characters from indexi
to indexn - 1
(both inclusive), with a cost ofn - i
Return the minimum cost to make all characters of the string equal.
Invert a character means if its value is ‘0’ it becomes ‘1’ and vice-versa.
c++
1 | class Solution { |