Maximum Number of Balloons

Problem Summary

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        countActual = {}
        for c in text:
            countActual[c] = countActual.get(c, 0) + 1
        
        target = "balloon"
        countNeeded = {}
        for c in target:
            countNeeded[c] = countNeeded.get(c, 0) + 1

        result = []
        for c in target:
            if c not in countActual:
                return 0
            result.append(countActual[c] // countNeeded[c])
        
        return min(result)