Tax Calculation with Year and Filing Rules
Updated
Problem statement
Calculate tax for taxableIncome, expressed in integer cents. Tax rules are supplied in parallel arrays. Rule i applies when ruleYears[i] == year and ruleStatuses[i] equals filingStatus. Exactly one rule matches.
For a matching rule, bracketEnds[i][j] is the exclusive upper income bound of marginal bracket j, and ratesBps[i][j] is its rate in basis points, where 100 basis points equal one percent. Brackets start at 0, are contiguous, and the final end covers taxableIncome. For each bracket, round that bracket's tax down to a whole cent, then sum the bracket taxes.
If customRateBps is nonnegative, it overrides the matching marginal rule. Return floor(taxableIncome * customRateBps / 10000). A value of -1 means no custom rate.
Function
calculateTax(taxableIncome: long, year: int, filingStatus: String, ruleYears: int[], ruleStatuses: String[], bracketEnds: long[][], ratesBps: int[][], customRateBps: int) → longExamples
Example 1
taxableIncome = 100000year = 2026filingStatus = "single"ruleYears = [2026]ruleStatuses = ["single"]bracketEnds = [[50000,100000]]ratesBps = [[1000,2000]]customRateBps = -1return = 15000The first 50000 cents are taxed at 10% for 5000 cents, and the next 50000 at 20% for 10000 cents.
Example 2
taxableIncome = 100000year = 2026filingStatus = "single"ruleYears = [2026]ruleStatuses = ["single"]bracketEnds = [[50000,100000]]ratesBps = [[1000,2000]]customRateBps = 1500return = 15000The custom 15% rate overrides the marginal brackets.
Example 3
taxableIncome = 60000year = 2025filingStatus = "joint"ruleYears = [2025,2025]ruleStatuses = ["single","joint"]bracketEnds = [[30000,100000],[40000,100000]]ratesBps = [[1000,2000],[500,1000]]customRateBps = -1return = 4000The joint rule applies: 40000 cents at 5% plus 20000 cents at 10%.
Constraints
0 <= taxableIncome <= 10^12.1 <= ruleYears.length == ruleStatuses.length == bracketEnds.length == ratesBps.length <= 1000.- Exactly one rule matches
yearandfilingStatus. - Each rule has 1 to 50 strictly increasing positive bracket ends, and its final end is at least
taxableIncome. - Each rate is between
0and10000basis points. customRateBps == -1or0 <= customRateBps <= 10000.
More Gusto Onsite Interview questions
Similar questions at other companies
- Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
- Spiral MatrixAthenahealth · ONSITE INTERVIEW
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW
- Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions