Colored Squares
InterviewTime limit1sMemory limit512 MB
Delete at most k squares from a colored row so that the longest run of one color is as large as possible, and output that maximum run length.
- Level
Medium6 of 10
- Topics
- Two pointers, Sliding window, Array, Binary search
- Solved
- No attempts yet
Problem
Graphic design is Aditya's new passion. He has launched his new company, Turmeric, and his first client comes to him to design a new logo. The old logo consists of colored squares in a row. The -th square is painted in a color represented by a number such that , where is the total number of colors in the logo. Now, the client is a very picky person. He will not allow Aditya to change any of the square's colors but he will give Aditya the artistic freedom to delete up to squares in the logo. Aditya thinks that the aesthetic score of a logo is equal to the maximum number of consecutive squares with the same color. Help Aditya figure out how to remove at most squares such that the aesthetic score of the new logo is maximized. Aditya may choose to not remove any squares.
Input
The first line of input is integers separated by spaces , , and such that , , and
The next line is integers separated by spaces representing the color of each square in the pattern, such that .
Output
Output a single integer, the maximum possible aesthetic score of the new logo.