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.
As mentioned in the editorial, idea is, except the "sub string" to be removed, rest of the string state should be steady (i.e each charecter count less than n/4).
The string is not steady due to fact that, one or many of ACTG letter is more than n/4.
Solution is - Keep removing letters from original string till you get a string where state is steady. i.e the charecters count is less than n/4.
In the solution, "j" counter in while loop keeps removing charecters (by reducing the count).
During this removal, we might have removed few necessary charecters which are still needed. This charecter is added back at the end of for loop, to get the optimal solution.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bear and Steady Gene
You are viewing a single comment's thread. Return to all comments →
As mentioned in the editorial, idea is, except the "sub string" to be removed, rest of the string state should be steady (i.e each charecter count less than n/4). The string is not steady due to fact that, one or many of ACTG letter is more than n/4.
Solution is - Keep removing letters from original string till you get a string where state is steady. i.e the charecters count is less than n/4.
In the solution, "j" counter in while loop keeps removing charecters (by reducing the count).
During this removal, we might have removed few necessary charecters which are still needed. This charecter is added back at the end of for loop, to get the optimal solution.