Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Progressive Tax Calculation Algorithm
00:00
5 left

Progressive Tax Calculation Algorithm

HardPython

Problem

NetSuite tax configurations can contain progressive ranges whose order is not guaranteed. Given an income or transaction amount and a collection of contiguous tax brackets, calculate the total progressive tax owed.

Each bracket is represented as [lower, upper, rate_bps], where bounds are measured in cents, lower is inclusive, upper is exclusive, and rate_bps is the tax rate in basis points. The final bracket uses null for upper to represent no upper limit. Brackets may be provided in any order.

Implement calculate_progressive_tax(brackets, amount_cents). Return the tax in cents, rounded to the nearest cent, with exact half-cent values rounded upward. Use integer arithmetic for the calculation.

Constraints

  • 1 <= len(brackets) <= 10^5
  • 0 <= amount_cents <= 10^18
  • 0 <= lower < upper for finite ranges
  • 0 <= rate_bps <= 10000
  • Brackets are contiguous and non-overlapping
  • Brackets cover every amount from zero upward
  • Exactly one bracket has upper = null

Function Signature

def calculate_progressive_tax(brackets, amount_cents):
Interviewer

Your question is Progressive Tax Calculation Algorithm. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.