Rangers at a wilderness trailhead log every radio check-in from hikers entering the backcountry. Each check-in records the hiker's identifier and the calendar date it happened. For a safety audit, the rangers want to know, for every day within the 30 days ending on a chosen audit date (inclusive), how many distinct hikers checked in that day — but only for days that actually saw at least one check-in.
Given the audit date and the full list of check-in records, report the distinct-hiker count for every day inside the trailing 30-day window that has at least one check-in, ordered from earliest date to latest. A hiker who checks in more than once on the same day (perhaps at different stations) is only counted once for that day. Check-ins on dates outside the window must be ignored entirely.
The first line contains the audit date in YYYY-MM-DD format followed by an integer n, the number of check-in records.
Each of the next n lines (or whitespace-separated tokens) contains an integer hiker id followed by a check-in date in YYYY-MM-DD format.
For every date d inside the inclusive window [auditDate - 29 days, auditDate] for which at least one check-in exists, print a line d count, where count is the number of distinct hiker ids that checked in on d. Print the lines in ascending order of date. Print nothing for a day with zero check-ins, and print no output at all if no date in the window has any check-in.
YYYY-MM-DD format.Example 1
Input
2021-05-15 6 11 2021-04-20 12 2021-04-20 11 2021-04-20 13 2021-05-01 11 2021-05-01 99 2021-03-01
Expected
2021-04-20 2 2021-05-01 2
Explanation
The audit date is 2021-05-15, so the 30-day window runs from 2021-04-16 through 2021-05-15 inclusive. On 2021-04-20 hikers 11 and 12 check in (hiker 11's duplicate check-in that day is not counted twice), giving 2 distinct hikers. On 2021-05-01 hikers 13 and 11 check in, giving 2 distinct hikers. The check-in by hiker 99 on 2021-03-01 falls well before the window and is ignored. Sorted by date: '2021-04-20 2' then '2021-05-01 2'.
Example 2
Input
2022-01-31 4 5 2022-01-31 6 2022-02-01 7 2022-01-02 8 2022-01-01
Expected
2022-01-02 1 2022-01-31 1
Explanation
The audit date is 2022-01-31, so the window runs from 2022-01-02 (exactly 29 days earlier) through 2022-01-31 inclusive. Hiker 5's check-in on 2022-01-31 sits right at the end of the window and counts. Hiker 6's check-in on 2022-02-01 is one day after the audit date and is excluded. Hiker 7's check-in on 2022-01-02 sits exactly at the start of the window and counts. Hiker 8's check-in on 2022-01-01 is one day before the window starts and is excluded. Sorted by date: '2022-01-02 1' then '2022-01-31 1'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →