Magicsheet logo

Calculate Amount Paid in Taxes

Easy
83.4%
Updated 6/1/2025

Calculate Amount Paid in Taxes

What is this problem about?

The Calculate Amount Paid in Taxes interview question involves calculating progressive income tax based on brackets. You are given a 2D array brackets where each entry is [upper_limit, percent] and an income value. Each bracket applies to the portion of income that falls between its upper limit and the previous bracket's limit. This Calculate Amount Paid in Taxes coding problem is a simulation of financial logic.

Why is this asked in interviews?

Stripe and Bloomberg use this to test a candidate's ability to handle ranges and iterative calculations. It requires careful subtraction to determine the "taxable amount" within each specific bracket. It's a great test for precision (handling floating point results) and boundary conditions (income exactly at a bracket limit).

Algorithmic pattern used

This follows the Array, Simulation interview pattern. You iterate through the brackets, calculating how much of the user's income falls into the current slice, applying the percentage, and adding it to a running total.

Example explanation

Brackets: [[3, 50], [7, 10], [12, 25]], Income: 10

  1. First 3:Taxedat503: Taxed at 50%. Tax = 1.5.
  2. Next 4(4 (3 to 7):Taxedat107): Taxed at 10%. Tax = 0.4.
  3. Next 3(3 (7 to 10):Taxedat2510): Taxed at 25%. Tax = 0.75. Total Tax: 1.5 + 0.4 + 0.75 = 2.65. Note that the remaining 2(2 (10 to $12) from the last bracket is not taxed because the income ended at 10.

Common mistakes candidates make

  • Taxing the whole limit: Applying the tax rate to the upper_limit instead of the width of the bracket.
  • Going past income: Continuing to calculate taxes for brackets that are higher than the actual income.
  • Floating point errors: Not correctly handling decimal division when calculating percentages.

Interview preparation tip

In progressive calculation problems, always keep track of the "previous limit." This allows you to calculate the delta (current - previous) which is the actual taxable amount for that specific tier. Clear variable naming (e.g., taxable_income, bracket_width) helps avoid logic errors.

Similar Questions