Back to Practice
#0204

Train/Test Split by Time

MediumML25 min20 XP

Problem

Given rows sorted by date and a cutoff date, return train rows before cutoff and test rows on or after cutoff.

Why This Matters

Time-based leakage is one of the easiest ways to make a model look good offline and fail in production.

Function Signature

def split_by_cutoff(rows, cutoff):

Examples

Example 1
Input[2026-01-01, 2026-01-05, 2026-02-01], cutoff = 2026-02-01
Output2 train rows, 1 test row

Rows before February go to train; February 1 goes to test.

Constraints

  • Return the exact requested result.
  • Handle common edge cases.
  • Keep the solution readable before optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[2026-01-01, 2026-01-05, 2026-02-01], cutoff = 2026-02-01
Expected2 train rows, 1 test row

Rows before February go to train; February 1 goes to test.

Hidden Test Categories
empty or minimal inputrepeated valueslarger realistic input