Easy
ArraySimulation
Updated Sep 2026

Calculate Amount Paid in Taxes

Asked at Snowflake

Problem

Calculate Amount Paid in Taxes gives you progressive tax brackets [upper, percent] sorted by upper bound, and an income. Each slice of income between consecutive upper bounds is taxed at that bracket's rate. Return the total tax. It checks that you can walk ranges carefully without off-by-one errors.

Asked At

CompanyDifficulty
SnowflakeEasyView all Snowflake questions →

How to Think About It

1.

Bracket i covers income from the previous upper bound (0 for the first) up to upper_i.

2.

The taxable amount in a bracket is min(income, upper_i) - prev, clamped at 0. Multiply by percent_i / 100 and add it up.

3.

Stop as soon as income <= upper_i — higher brackets do not apply.

4.

Walkthrough: brackets [[3,50],[7,10],[12,25]], income 10: 3 * 0.50 + 4 * 0.10 + 3 * 0.25 = 1.5 + 0.4 + 0.75 = 2.65.

5.

The result is a floating-point number; answers within 10^-5 are accepted.

Optimal Approach

Step 1: tax = 0, prev = 0.
Step 2: For each (upper, percent):
taxable = min(income, upper) - prev
If taxable <= 0, stop.
tax += taxable * percent / 100
prev = upper.
Step 3: Return tax.

Time: O(b). Space: O(1).

What Trips People Up in Real Interviews

1.

Taxing the whole income at the highest applicable rate. Progressive tax applies each rate only to its own slice.

2.

Integer division in C++/Java (percent / 100 becomes 0). Divide as a double.

3.

Continuing past the bracket that contains the income and adding negative amounts.

4.

Forgetting that the first bracket starts at 0.

Solution Code

def calculateTax(brackets, income):
    tax = 0.0
    prev = 0
    for upper, percent in brackets:
        taxable = min(income, upper) - prev
        if taxable <= 0:
            break
        tax += taxable * percent / 100
        prev = upper
    return tax

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Calculate Amount Paid in Taxes problem?

Calculate Amount Paid in Taxes gives you progressive tax brackets `[upper, percent]` sorted by upper bound, and an income. Each slice of income between consecutive upper bounds is taxed at that bracket's rate. Return the total tax. It checks that you can walk ranges carefully without off-by-one errors.

How do you solve Calculate Amount Paid in Taxes?

The optimal approach is described in detail above, including step-by-step walkthroughs, complexity analysis, and solution code in Python. Scroll up to the "Optimal Approach" section.

What companies ask Calculate Amount Paid in Taxes?

Calculate Amount Paid in Taxes is asked at Snowflake. It is a easy difficulty problem.

What are common mistakes on Calculate Amount Paid in Taxes?
  • Taxing the whole income at the highest applicable rate. Progressive tax applies each rate only to its own slice.
  • Integer division in C++/Java (`percent / 100` becomes 0). Divide as a double.
  • Continuing past the bracket that contains the income and adding negative amounts.
  • Forgetting that the first bracket starts at 0.