Skip to content

Practice Calculate Amount Paid in Taxes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2303
LeetCode Problem

Calculate Amount Paid in Taxes

Problem Statement

brackets lists increasing upper income bounds and their percentage rates. Tax the portion from zero through the first bound at the first rate, the portion above that bound through the next at the next rate, and so on. Tax only the portions actually earned, rather than applying one rate to all income. Return total tax for income; answers within 10^-5 are accepted.

Source: Calculate Amount Paid in Taxes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
brackets = [[3,50],[7,10],[12,25]], income = 10
Output
2.65000

# Example 2

Input
brackets = [[1,0],[4,25],[5,50]], income = 2
Output
0.25000

# Example 3

Input
brackets = [[2,50]], income = 0
Output
0.00000

Constraints

1 <= brackets.length <= 100
1 <= upperi <= 1000
0 <= percenti <= 100
0 <= income <= 1000
upperi is sorted in ascending order.
All the values of upperi are unique.
The upper bound of the last tax bracket is greater than or equal to income.

Related LeetCode Problems

Practice more problems similar to Calculate Amount Paid in Taxes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.