We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Bear and Steady Gene
You are viewing a single comment's thread. Return to all 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.