Interview Query

Weekly Aggregation

14
Have you seen this question before?

Given a list of timestamps in sequential order, return a list of lists grouped by week (7 days) using the first timestamp as the starting point.

Example:

Input:

ts = [
    '2019-01-01', 
    '2019-01-02',
    '2019-01-08', 
    '2019-02-01', 
    '2019-02-02',
    '2019-02-05',
]

Output:

def weekly_aggregation(ts) -> [
    ['2019-01-01', '2019-01-02'], 
    ['2019-01-08'], 
    ['2019-02-01', '2019-02-02'],
    ['2019-02-05'],
]
Next question: Best Measure
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code