You are given a strngstring s of size n, consisting of characters A and B only. Ram wantsYou have to take out two disjoint segments out of its and he will count the number of As inside those segments, let us call this quantity x andfind minimum sum of size of the two disjoint segments y. You have to find minimum yof the string s such that there exists two disjoint segments which have their x quantitynumber of A's in them are >= z.
Input: string s, n, x and 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?