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
Average Task Time Calculation
00:00
5 left

Average Task Time Calculation

MediumPython

Problem

The Noom app stores a baseline daily assignment schedule and temporary assignment overrides. Write a function that returns the arithmetic average assignment value for every calendar day in an inclusive date range.

A baseline interval and a temporary assignment contain start, end, and numeric value fields. Dates use the YYYY-MM-DD format. Baseline intervals are non-overlapping and cover every requested day. Temporary assignments are non-overlapping, and override the baseline on their covered dates. The range may contain days with no temporary assignment.

Formal Specification

Implement average_assignment(baseline, temporary_assignments, start_date, end_date), where baseline and temporary_assignments are lists of dictionaries and each date interval is inclusive. Return a floating-point number equal to the sum of the effective daily values divided by the number of days in the requested range. Do not iterate over every date in the range.

Constraints

  • 1 <= len(baseline) + len(temporary_assignments) <= 10^5
  • Dates are valid Gregorian dates from 1900-01-01 through 2100-12-31
  • Every interval has start <= end
  • The requested range is inclusive and covered by baseline intervals
  • Baseline and temporary intervals are non-overlapping within their respective lists
  • Values are integers or finite floating-point numbers

Function Signature

def average_assignment(baseline, temporary_assignments, start_date, end_date):
Interviewer

Your question is Average Task Time Calculation. 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.