Beautiful String

Limits 10s, 512 MB

You are given a binary string S of length N, and a value K. You need to find a maximum length of a beautiful string which is a sub-string of S. A beautiful string is a binary string where absolute difference of zero’s and one’s occurrence is no more than K.

This is a companion discussion topic for the original entry at