Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Task Time Calculation

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Average Task Time Calculation. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output