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 upper bound (i.e. upperi-1 &lt; upperi for 0 &lt; i &lt; brackets.length).

Tax is calculated as follows:


	The first upper0 dollars earned are taxed at a rate of percent0.
	The next upper1 - upper0 dollars earned are taxed at a rate of percent1.
	The next upper2 - upper1 dollars earned are taxed at a rate of percent2.
	And so on.


You are given an integer income representing the amount of money you earned. Return the amount of money that you have to pay in taxes. Answers within 10-5 of the actual answer will be accepted.

&nbsp;
Example 1:

Input: brackets = [[3,50],[7,10],[12,25]], income = 10
Output: 2.65000
Explanation:
Based on your income, you have 3 dollars in the 1st tax bracket, 4 dollars in the 2nd tax bracket, and 3 dollars in the 3rd tax bracket.
The tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.
In total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.


Example 2:

Input: brackets = [[1,0],[4,25],[5,50]], income = 2
Output: 0.25000
Explanation:
Based on your income, you have 1 dollar in the 1st tax bracket and 1 dollar in the 2nd tax bracket.
The tax rate for the two tax brackets is 0% and 25%, respectively.
In total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.


Example 3:

Input: brackets = [[2,50]], income = 0
Output: 0.00000
Explanation:
You have no income to tax, so you have to pay a total of $0 in taxes.


&nbsp;
Constraints:


	1 &lt;= brackets.length &lt;= 100
	1 &lt;= upperi &lt;= 1000
	0 &lt;= percenti &lt;= 100
	0 &lt;= income &lt;= 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.


class Solution:
    def calculateTax(self, brackets: List[List[int]], income: int) -> float:
        taxtot=0
        if(brackets[0][0]<income):
            taxtot+=brackets[0][0]*(brackets[0][1])
            income-=brackets[0][0]
        else:
            taxtot+=income*(brackets[0][1])
            return taxtot/100
        i=1
        while(income>0 and i<len(brackets)):
            if(income>(brackets[i][0]-brackets[i-1][0])):
                taxtot+=(brackets[i][0]-brackets[i-1][0])*brackets[i][1]
                income-=brackets[i][0]-brackets[i-1][0]
            else:
                taxtot+=income*brackets[i][1]
                income=0
            i+=1
        return taxtot/100
class Solution {
    public double calculateTax(int[][] brackets, int income) {
        double ans=0;
        int pre=0;
        for(int[] arr : brackets){
            int val=arr[0]; arr[0]-=pre;  pre=val;
            ans+=(double)(Math.min(income,arr[0])*arr[1])/100;
            income-=arr[0];
            if(income<=0){ break; }
        }
        return ans;
    }
}
class Solution {
public:
    double calculateTax(vector<vector<int>>& brackets, int income) 
    {    
        double tax = 0; 
        
        if(brackets[0][0]<=income) tax=(brackets[0][0]*brackets[0][1]/100.0);         
        else return (income*brackets[0][1]/100.0);
            
        for(int i=1; i<brackets.size(); i++)
        {
            if(brackets[i][0]<=income)
                    tax += ((brackets[i][0]-brackets[i-1][0])*brackets[i][1]/100.0);
            
            else 
            {
                tax += ((income-brackets[i-1][0])*brackets[i][1]/100.0);
                break;
            }
        }
        return tax;
        
    }
};
var calculateTax = function(brackets, income) {
    return brackets.reduce(([tax, prev], [upper, percent]) => {
        let curr = Math.min(income, upper - prev);
        tax += curr * (percent / 100);

        income -= curr;
        if (income <= 0) brackets.length = 0;

        return [tax, upper];
    }, [0, 0])[0];
};
Calculate Amount Paid in Taxes