Trains the technique from
LeetCode 2303Calculate Amount Paid in TaxesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A credit union bills its members a graduated service levy against their declared annual income.
You are handed the schedule as brackets. Entry i of it holds two numbers: a ceiling upper_i followed by a rate percent_i, and together they describe the i-th band of the schedule. The bands are listed with upper_i increasing. Band 0 covers income from 0 up to and including upper_0. For i > 0, band i covers the income above upper_(i-1) up to and including upper_i. Whatever portion of the income lands inside band i is billed at percent_i percent of that portion.
Given a member's income, return the levy owed on it.
The levy always works out to a whole number of hundredths of a currency unit. Return it as a decimal number; an answer is accepted when it is within 10^-5 of the correct levy.
Example 1
The first 3 of income is billed at 50 percent, giving 1.5. The next 4 is billed at 10 percent, giving 0.4. The remaining 3 falls in the third band at 25 percent, giving 0.75. Altogether that is 2.65.
Example 2
The first 4 of income attracts nothing, and the remaining 5 is billed in full, so the levy is 5.0.
Example 3
All 100 of income sits inside the first band, so it is billed at 20 percent for a levy of 20.0. The second band is never reached.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def calculate_tax(brackets: list[list[int]], income: int) -> float:public double calculateTax(int[][] brackets, int income)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.