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
Parse Payroll With Overtime Rules
00:00
5 left

Parse Payroll With Overtime Rules

HardPython

Problem

Write a function that parses complex, nested payroll data and calculates total earnings based on varying overtime rules. Implement calculate_total_earnings(payroll), where each payroll node contains employees and optional child nodes; child or employee rules override inherited rules. Rules are ordered cumulative hour brackets, and up_to: null means unlimited hours. Return total earnings rounded to two decimals. Example: 45 hours at $20 with rules 40 hours at 1x and remaining hours at 1.5x returns 950.0. Input is a JSON-compatible dictionary, and output is a number. Constraints: nested depth is at most 100, each node has at most 10,000 employees or children, and rules are ordered with nondecreasing limits.

Constraints

  • The top-level payroll object contains a nonempty rules list.
  • Each employee contains nonnegative numeric hours and hourly_rate values.
  • Each rule contains a positive numeric multiplier and an up_to value that is a nonnegative number or null.
  • Rules are ordered by nondecreasing up_to values, with at most one final null limit.
  • Nested payroll depth is at most 100.
  • Each node contains at most 10,000 employees or children.

Function Signature

def calculate_total_earnings(payroll):
Interviewer

Your question is Parse Payroll With Overtime Rules. 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.