Bear and Steady Gene

  • + 0 comments

    Initially, we have a window with length , representing that we would need to remove a window of size to make the gene valid. Our goal is to minimise this - i.e., remove the fewest characters possible (the smallest window possible) while still having the gene valid.

    This works, because we can always 'add' characters from the window we're removing, but not subtract them. Therefore, the condition for our window being valid is that the characters outside of the window all have a count less than (or equal to) the goal (to be supplemented with the characters inside the window). This can be simplified (in code) to simply track the max count of the characters.