title: Find number of bits to be flipped to get maximum 1's in array
body: <p>We have a bit array like below</p>
  
  <pre><code>{1 0 1 0 0 1 0 1}
  </code></pre>
  
  <p>Number of bits in above array is 8</p>
  
  <p>If we take range from <code>[1,5]</code> then number of bits in <code>[1,5]</code> range is <code>[0 1 0 0 1]</code>.<br>
  If we flip this range then after flipping it will be <code>[ 1 0 1 1 0]</code><br>
  So total number of 1's after flipping <code>[1,5]</code> range is <code>[1 1 0 1 1 0 0 1] = 5</code></p>
  
  <p>If we take range from <code>[1,6]</code> then number of bits in [1,6] range is <code>[0 1 0 0 1 0]</code>.<br>
  If we flip this range then after flipping it will be <code>[ 1 0 1 1 0 1]</code><br>
  So total number of 1's after flipping [1,5] range is <code>[1 1 0 1 1 0 1 1] = 6</code></p>
  
  <p>So the answer is  range <code>[1,6]</code> and after flipping we can get 6 1's in array</p>
  
  <p>Is there a good algorithm that can solve this problem. I an only think of dynamic programming because this problem can be broken down into sub problems which can be combined.</p>