Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.