Progressive Income Tax
Updated
Problem statement
A fictional tax schedule is given as ordered rows [upper, percent] in brackets. The first row taxes income from 0 up to its upper limit. Each later row taxes only the part of the income above the previous upper limit and up to the current upper limit. The rate is percent / 100 for that band.
Complete calculateTax(brackets, income) and return the total tax on the nonnegative integer income. Apply each rate only to the income inside its band, not to the whole income. The final upper limit always covers the income.
Each upper limit is greater than the one before it. Rates may go up or down, so keep the bands in their given order. Return the result with its fractional part. Do not round it to an integer or round the tax for each band separately. Answers within an absolute or relative error of 10^-9 are accepted.
Function
calculateTax(brackets: int[][], income: int) → doubleExamples
Example 1
brackets = [[3,50],[7,10],[12,25]]income = 10return = 2.65The first 3 units contribute 1.50, the next 4 contribute 0.40, and the remaining 3 contribute 0.75, for 2.65 in total.
Example 2
brackets = [[1,0],[4,25],[8,50]]income = 5return = 1.25The first unit contributes 0, the next 3 contribute 0.75, and one unit in the final band contributes 0.50, for 1.25.
Example 3
brackets = [[5,30],[10,60]]income = 0return = 0No income falls in any band, so the tax is 0.
Constraints
1 <= brackets.length <= 30.- Every row has exactly two integers
[upper, percent]. - Upper limits are strictly increasing and satisfy
1 <= upper <= 2000. 0 <= percent <= 100. Rates may rise, fall, or stay equal between bands.0 <= income <= brackets[brackets.length - 1][0].
More Snowflake Phone Screen questions
- Minimum StackPHONE SCREEN · Seen Nov 2026
- Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
- Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Monthly Calendar with Custom Week StartStripe · PHONE SCREENStripe interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
- Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
- Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
- Cumulative No-Intercept Regression BetasCitadel · PHONE SCREENCitadel interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions