Calculate Amount Paid in Taxes Problem
Calculate Amount Paid in Taxes Problem — ExecCode Easy DSA Practice
Solve the Calculate Amount Paid in Taxes problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed 2D integer array brackets where brackets[i] = [upperi, percenti] means that the i^th tax bracket has an upper bound of upperi and is taxed at a rate of percenti. Your task is to compute the required answer and return the amount of money that you have to pay in taxes. The brackets are sorted by upper bound (i.e. upperi-1 < upperi for 0 < i < brackets.length). Tax is calculated as follows: - The first upper0 dollars earned are taxed at a rate of percent0.
Examples
Input {"brackets": [[3, 50], [7, 10], [12, 25]], "income": 10}; Output 2.65. Input {"brackets": [[1, 0], [4, 25], [5, 50]], "income": 2}; Output 0.25
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.
Practice Calculate Amount Paid in Taxes free on ExecCode. Browse DSA problems, topic map, and placement guides.