title: Implementation of DGIM algorithm with k<N extension
body: <p>I implemented the DGIM algorithm using Python. Now I'm trying to extend the algorithm by finding the amount of 1's in the last k. When I understood everything correct I think I need to find the earliest bucket that overlaps with k and take half its size + the other buckets within k. But I don't really get how to do it.</p>
  <p>I found the image below. From my understanding I would take half of the size of the red circled bucket plus all of the blue ones. Could someone give me a hint for the implementation? Please correct me if I'm wrong.
  <a href="https://i.stack.imgur.com/Kk2lh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kk2lh.png" alt="enter image description here" /></a></p>