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
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
Get started
Time-Aware Train/Test Splits
00:00
5 left

Time-Aware Train/Test Splits

HardPython

Problem

How do you account for time dependencies when splitting data for model validation?

Implement time_series_splits(timestamps, initial_train_size, validation_size, n_splits, gap) using chronological expanding-window splits. Return a list of objects containing zero-based train and validation index arrays. Timestamps are strictly increasing, and each validation window must occur after its training window with exactly gap unused observations between them.

Constraints

  • 1 <= len(timestamps) <= 1000
  • timestamps are strictly increasing
  • 1 <= initial_train_size
  • 1 <= validation_size
  • 1 <= n_splits
  • 0 <= gap
  • initial_train_size + n_splits * (validation_size + gap) <= len(timestamps)

Function Signature

def time_series_splits(timestamps, initial_train_size, validation_size, n_splits, gap):
Interviewer

Your question is Time-Aware Train/Test Splits. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.