cswork / libraryOpen practice workspace

Coding questions · Interactive Brokers

Calculate Tax in a Progressive Marginal Tax System

Practice a Interactive Brokers coding interview problem focused on calculate tax in a progressive marginal tax system. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.

Implement a progressive marginal tax calculator. Brackets are sorted (lower_cutoff, rate) pairs. Each portion of income is taxed at the rate for its bracket until the next cutoff.

Implement:

def calculate_progressive_tax(brackets: list[tuple[float, float]], income: float) -> float:
    pass

Progressive Marginal Tax Calculator

Calculate total tax owed under sorted marginal tax brackets.

Examples

Example 1

Input: {"brackets":[[0,0.1],[10000,0.2],[50000,0.3]],"income":60000}
Output: 12000.0

Explanation: Progressive sample.

Example 2

Input: {"brackets":[[0,0.1]],"income":100}
Output: 10.0

Explanation: One bracket.