2025-08-18 16:52:53 +0000 UTC

Calculate Amount Paid in Taxes

Code

class Solution:
    def calculateTax(self, brackets: List[List[int]], income: int) -> float:
        tax = prev = 0
        for upper, perc in brackets:
            if income >= upper:
                tax += (upper - prev) * perc / 100
                prev = upper
            else:
                tax += (income - prev) * perc / 100
                return tax
        return tax