Calculate Amount Paid in Taxes
Examples
Example 1:
Input: brackets = [[3,50],[7,10],[12,25]], income = 10
Output: 2.65
Example 2:
Input: brackets = [[1,0],[4,25],[5,50]], income = 2
Output: 0.25
Example 1:
Input: brackets = [[3,50],[7,10],[12,25]], income = 10
Output: 2.65
Example 2:
Input: brackets = [[1,0],[4,25],[5,50]], income = 2
Output: 0.25
You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the ith tax bracket has an upper bound of upperi and is taxed at a rate of percenti.
The brackets are sorted by upperi in ascending order, and each upper bound is guaranteed to be unique.
Tax is computed progressively: income up to the first bracket is taxed at its rate, then income in each subsequent bracket is taxed at that bracket's rate.
Given an integer income, return the amount of tax paid.
1 <= brackets.length <= 1001 <= upperi <= 10000 <= percenti <= 1000 <= income <= 1000upperi < upper(i + 1)