text. A move works like this: choose a position i that has a letter equal to text[i] somewhere on its left and somewhere on its right. Then erase the nearest such letter on the left of i and the nearest one on its right. The letter at i itself stays.
You may make as many moves as you like. Return the smallest length the string can reach.text="xxxyxx" → 2
There are five xs: pick a middle one and erase its nearest x on each side, then do it once more, leaving one x. The lone y cannot be touched. That gives 2.
text="mmnn" → 4
No letter has a copy of itself on both sides, so the string stays as it is.
text="aaaa" → 2
Pick the second a and erase the first and the third, leaving two as and no more moves.
text consists of lowercase English letterstext="xxxyxx"
2
Run checks the first 3 tests in your browser. Submit checks all 50 tests on the server, hidden ones included.