Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.