Find number of bits to be flipped to get maximum 1's in array | miafish
We have a bit array like below
{1 0 1 0 0 1 0 1}
Number of bits in above array is 8
If we take range from [1,5]
then number of bits in [1,5]
range is [0 1 0 0 1]
.
If we flip this range then after flipping it will be [ 1 0 1 1 0]
So total number of 1's after flipping [1,5]
range is [1 1 0 1 1 0 0 1] = 5
If we take range from [1,6]
then number of bits in [1,6] range is [0 1 0 0 1 0]
.
If we flip this range then after flipping it will be [ 1 0 1 1 0 1]
So total number of 1's after flipping [1,5] range is [1 1 0 1 1 0 1 1] = 6
So the answer is range [1,6]
and after flipping we can get 6 1's in array
Read full article from Find number of bits to be flipped to get maximum 1's in array | miafish
No comments:
Post a Comment