intminimumOperation(string str){ int n = str.size(); int count[3] = {0};
for (char ch: str) { ++count[ch - 'A']; }
int need[3] = {0}; int m[3] = {0}; int needValid = 0; for (int i = 0; i < 3; ++i) { if (count[i] > n / 3) { need[i] = count[i] - n / 3; ++needValid; } }
if (needValid == 0) { return0; } if (needValid == 1) { return2; }
int left = 0, right = 0; int valid = 0; while (right < n) { char ch = str[right++]; if (need[ch - 'A'] > 0) { ++m[ch - 'A']; if (m[ch - 'A'] == need[ch - 'A']) { ++valid; } } if (valid == needValid) { // cout << left << " " << right << endl; return1; }