You are given a string s of size n, consisting of characters A and B only. You have to find minimum sum of size of the two disjoint segments of the string s such that number of A's in them are >= z.
Input: string s, n, z are given in the input. Output: minimum sum of size of two disjoint segments with given property
Currently I have a solution of complexity $\mathbf{O}(n^2)$, Can anybody give a better solution than this?
Or can somebody prove that it is somehow related to 3 SUM problem?