Skip to main content
3 of 3
deleted 89 characters in body

Minimize the length of two disjoint segments in the string with given property

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?