3223. Minimum Length of String After Operations
Hint
class Solution {
public:
int minimumLength(string s)
{
// Initialize n to the size of the input string s
// Initialize a frequency vector for the 26 lowercase English letters
// Iterate over each character in the string
for ()
{
// Increment the frequency count for the current character
// If the frequency of the current character reaches 3
// Reduce the frequency count by 2 (essentially removing 2 instances)
// Decrease the length of the string by 2
}
// Return the adjusted length of the string
}
};
class Solution {
public:
int minimumLength(string s)
{
int n = s.size();
vector<int> freq(26);
for (char c : s)
{
++freq[c - 'a'];
if (freq[c - 'a'] == 3)
{
freq[c - 'a'] -= 2;
n -= 2;
}
}
return n;
}
};