Tap here to switch tabs
Problem
Submissions

Problem: Calculate Amount Paid in Taxes

Try to solve the Calculate Amount Paid in Taxes problem.

Statement

You are given a 00 indexed 2extD2 ext{D} integer array brackets where brackets[i] = [upper_i, percent_i] indicates that the iextthi^{ ext{th}} tax bracket has an upper bound of upper_i and is taxed at a rate of percent_i percent. The brackets are sorted in strictly increasing order by their upper bounds.

You are also given an integer income representing your total income.

The amount of tax paid is calculated as follows:

  • The first bracket taxes the portion of income from 00 up to upper_0 at a rate of percent_0 percent.

  • Each subsequent bracket taxes the portion of income that lies strictly between the previous bracket’s upper bound and upper_i at a rate of percent_i percent.

  • If income is less than an upper bound, only the amount earned within that bracket is taxed.

Return the total amount paid in taxes. Answers within 10−510^{-5} of the actual answer will be accepted.

Constraints:

  • 1≤1 \leq brackets.length ≤100\leq 100

  • 1≤1 \leq upper_i ≤1000\leq 1000

  • 0≤0 \leq percent_i ≤100\leq 100

  • 0≤0 \leq income ≤1000\leq 1000

  • upper_i is sorted in ascending order.

  • All the values of upper_i are unique.

  • The upper bound of the last tax bracket is greater than or equal to income.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Calculate Amount Paid in Taxes

Try to solve the Calculate Amount Paid in Taxes problem.

Statement

You are given a 00 indexed 2extD2 ext{D} integer array brackets where brackets[i] = [upper_i, percent_i] indicates that the iextthi^{ ext{th}} tax bracket has an upper bound of upper_i and is taxed at a rate of percent_i percent. The brackets are sorted in strictly increasing order by their upper bounds.

You are also given an integer income representing your total income.

The amount of tax paid is calculated as follows:

  • The first bracket taxes the portion of income from 00 up to upper_0 at a rate of percent_0 percent.

  • Each subsequent bracket taxes the portion of income that lies strictly between the previous bracket’s upper bound and upper_i at a rate of percent_i percent.

  • If income is less than an upper bound, only the amount earned within that bracket is taxed.

Return the total amount paid in taxes. Answers within 10−510^{-5} of the actual answer will be accepted.

Constraints:

  • 1≤1 \leq brackets.length ≤100\leq 100

  • 1≤1 \leq upper_i ≤1000\leq 1000

  • 0≤0 \leq percent_i ≤100\leq 100

  • 0≤0 \leq income ≤1000\leq 1000

  • upper_i is sorted in ascending order.

  • All the values of upper_i are unique.

  • The upper bound of the last tax bracket is greater than or equal to income.