3455. Minimum Length of String After Operations
My accepted Python solution to LeetCode problem 3455, Minimum Length of String After Operations, running in 147ms.
- Difficulty: Medium
- Python
- Runtime 147ms
- Memory 19.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 147ms, memory 19.2MB, accepted 2025-12-31.
class Solution:
def minimumLength(self, s: str) -> int:
from collections import Counter
# Count frequency of each character
freq = Counter(s)
# For each character, we can delete pairs of same characters
# on both sides of any occurrence
# The minimum remaining is 1 if odd count, 2 if even count >= 2
result = 0
for count in freq.values():
if count % 2 == 1:
result += 1
else:
result += 2
return result