2303. Calculate Amount Paid in Taxes

Easy

205

235

You are given a **0-indexed** 2D integer array `brackets`

where `brackets[i] = [upper`

means that the _{i}, percent_{i}]`i`

tax bracket has an upper bound of ^{th}`upper`

and is taxed at a rate of _{i}`percent`

. The brackets are _{i}**sorted** by upper bound (i.e. `upper`

for _{i-1} < upper_{i}`0 < i < brackets.length`

).

Tax is calculated as follows:

- The first
`upper`

dollars earned are taxed at a rate of_{0}`percent`

._{0} - The next
`upper`

dollars earned are taxed at a rate of_{1}- upper_{0}`percent`

._{1} - The next
`upper`

dollars earned are taxed at a rate of_{2}- upper_{1}`percent`

._{2} - 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`

of the actual answer will be accepted.^{-5}

**Example 1:**

Input:brackets = [[3,50],[7,10],[12,25]], income = 10Output:2.65000Explanation:Based on your income, you have 3 dollars in the 1^{st}tax bracket, 4 dollars in the 2^{nd}tax bracket, and 3 dollars in the 3^{rd}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 = 2Output:0.25000Explanation:Based on your income, you have 1 dollar in the 1^{st}tax bracket and 1 dollar in the 2^{nd}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 = 0Output:0.00000Explanation:You have no income to tax, so you have to pay a total of $0 in taxes.

**Constraints:**

`1 <= brackets.length <= 100`

`1 <= upper`

_{i}<= 1000`0 <= percent`

_{i}<= 100`0 <= income <= 1000`

`upper`

is sorted in ascending order._{i}- All the values of
`upper`

are_{i}**unique**. - The upper bound of the last tax bracket is greater than or equal to
`income`

.

Accepted

30.1K

Submissions

46.9K

Acceptance Rate

64.1%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved