Ctrl K

Tax by Bands

Easy
A country uses a progressive income tax. The scale is a list of bands bands, where bands[i] = [upper, percent]: income up to and including upper (above the previous limit) is taxed at percent percent. Bands are sorted by upper in increasing order. So the first bands[0][0] coins are taxed at the first band's rate, the next bands[1][0] - bands[0][0] coins at the second band's rate, and so on. Return the total tax owed on income. Answers within 10⁻⁵ of the exact value are accepted.
Example 1
bands=[[4, 10], [10, 30], [20, 50]], income=15 → 4.7

The first 4 coins are taxed at 10% (0.4), the next 6 at 30% (1.8), the remaining 5 at 50% (2.5). Total 4.7.

Example 2
bands=[[2, 0], [6, 20]], income=3 → 0.2

Two coins fall into the tax-free first band, and one coin in the second band costs 0.2.

Example 3
bands=[[5, 40]], income=0 → 0.0
Constraints
  • 1 ≤ len(bands) ≤ 100
  • 1 ≤ upper ≤ 1000
  • 0 ≤ percent ≤ 100
  • 0 ≤ income ≤ 1000
  • The upper values are strictly increasing
  • The last upper is at least income
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Long the Light Stayed On EasyRepack the Tray EasyQuiz Score Log EasyMirror and Negate a Bitmap EasySwap Rows and Columns Easy
loading Python…
Input
bands=[[4, 10], [10, 30], [20, 50]], income=15
Expected
4.7

Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.