text and a two-letter string pair. You must insert exactly one letter, either pair[0] or pair[1], anywhere in text (the very beginning and the very end are allowed too).
Return the largest possible number of times pair occurs as a subsequence of the resulting string. Occurrences are told apart by the positions of the chosen letters.
A subsequence is obtained by deleting some characters of a string (possibly none) without changing the order of the rest.text="xyzxy", pair="xy" → 5
Right now xy occurs as a subsequence three times. Adding an x at the front gives xxyzxy with five occurrences; adding a y at the end also gives five.
text="bab", pair="ba" → 3
Put a b at the front: bbab. Each of the three bs comes before the only a, so the answer is 3.
text="ooo", pair="oo" → 6
len(text) ≤ 10⁵len(pair) = 2text and pair consist of lowercase Latin letterstext="xyzxy", pair="xy"
5
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.