Friday, July 7th

 Trying to maximize student's confusion is today's problem.  Given a collection of test answers that are either true of false, try to flip up to k answers on the test to form the most consecutive "trues" or "falses" possible

There are several ways to solve the problem using Sliding Window.  The sliding window approach is based on whether the given string in the window is valid.   Validity is determined by the frequency of the minimum occuring character in the string - if it's less than or equal to k, the string is valid.

With this in mind, a Sliding Window solution can be implemented in the same way as yesterday, with a while loop nested in a for loop.  Starting from index 0, increment the right side of a window and test for validity.  If the string is invalid, increment the left side until the string is valid again.  Calculate the size and store the max size.  Return the maximum size.


Comments

Popular posts from this blog

Wednesday, September 20th

Monday, September 11th

Tuesday, September 19th