3223. Minimum Length of String After Operations

Tapan RachchhTapan Rachchh
1 min read
class Solution:
    def minimumLength(self, s: str) -> int:
        c = Counter(s)

        def removals(n):
            if n >= 3:
                if n % 2 == 0 :
                    return n - 2
                return n - 1

            return 0

        total = 0
        for e in c:
            x = c.get(e)
            total += removals(x)

        return len(s) - total
0
Subscribe to my newsletter

Read articles from Tapan Rachchh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tapan Rachchh
Tapan Rachchh