Date Range Generator - Problem
Given a start date start, an end date end, and a positive integer step, return a generator object that yields dates in the range from start to end inclusive.
The value of step indicates the number of days between consecutive yielded values. All yielded dates must be in the string format YYYY-MM-DD.
Note: The generator should yield dates chronologically and include both start and end dates if they fall on valid step intervals.
Input & Output
Example 1 — Basic Weekly Step
$
Input:
start = "2023-01-01", end = "2023-01-15", step = 7
›
Output:
["2023-01-01", "2023-01-08", "2023-01-15"]
💡 Note:
Starting from 2023-01-01, add 7 days each time: 2023-01-01 → 2023-01-08 → 2023-01-15. All dates are within range.
Example 2 — Daily Step
$
Input:
start = "2023-02-28", end = "2023-03-03", step = 1
›
Output:
["2023-02-28", "2023-03-01", "2023-03-02", "2023-03-03"]
💡 Note:
Step of 1 day across month boundary. February ends on 28th (2023 is not leap year), so next date is March 1st.
Example 3 — Large Step
$
Input:
start = "2023-01-01", end = "2023-01-10", step = 15
›
Output:
["2023-01-01"]
💡 Note:
First date is 2023-01-01. Next would be 2023-01-16 which exceeds end date 2023-01-10, so only start date is yielded.
Constraints
- start and end are valid dates in format YYYY-MM-DD
- start ≤ end
- 1 ≤ step ≤ 1000
- Date range will not exceed 10 years
Visualization
Tap to expand
Understanding the Visualization
1
Input
Start date, end date, and step size (days)
2
Process
Generate dates by adding step days repeatedly
3
Output
Array of date strings in YYYY-MM-DD format
Key Takeaway
🎯 Key Insight: Use generator functions with built-in date libraries to handle complex date arithmetic automatically
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code