#C1512. Longest Purchase Streak

    ID: 44726 Type: Default 1000ms 256MiB

Longest Purchase Streak

Longest Purchase Streak

You are given the purchase history of multiple customers. For each customer, a sequence of purchase dates is provided in the format YYYY-MM-DD. Your task is to compute the longest consecutive streak of purchase days for each customer. Two dates are considered consecutive if the difference between them is exactly one day.

A purchase streak is defined as a maximal sequence of dates \(d_1, d_2, \ldots, d_k\) such that for every \(1 \leq i < k\), \(d_{i+1} - d_i = 1\). You may use libraries or implement your own date difference logic. For instance, one common method to convert a date to an integer day count is: $$d = 365 \times year + \lfloor\tfrac{year}{4}\rfloor - \lfloor\tfrac{year}{100}\rfloor + \lfloor\tfrac{year}{400}\rfloor + \frac{153 \times month - 457}{5} + day - 306,$$ although you are free to use any correct approach.

If a customer has no purchase dates, the longest streak is 0.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \(C\) representing the number of customers.
  • For each customer, there is:
    • A line with a single integer \(N\) indicating the number of purchase dates.
    • If \(N > 0\), the next line contains \(N\) space-separated strings, each representing a purchase date in the format YYYY-MM-DD.

Note: When \(N = 0\), no date line is provided for that customer.

outputFormat

Print a single line to stdout containing \(C\) space-separated integers. Each integer represents the longest consecutive purchase streak for the corresponding customer.

## sample
3
5
2022-01-02 2022-01-03 2022-01-04 2022-01-06 2022-01-07
4
2021-12-25 2021-12-26 2021-12-27 2021-12-29
3
2023-01-10 2023-02-14 2023-02-15
3 3 2