A community-service nonprofit runs a rolling 30-day audit before certifying volunteers for a service award. Every time a volunteer checks in for a shift, the system logs the volunteer's ID, the shift's ID, and the calendar date -- sometimes the same check-in gets logged more than once by mistake. For a given audit window (a fixed end date together with the 29 days immediately before it, 30 calendar days total, inclusive on both ends), a volunteer counts as "active" if at least one of their logged entries falls inside that window. For every active volunteer, the nonprofit wants the number of distinct shift IDs they logged inside the window, and then the average of that count across all active volunteers.
YYYY-MM-DD.n (0 <= n <= 100000), the number of log entries.n lines contains three space-separated tokens: volunteerId shiftId date, where volunteerId and shiftId are integers (1 <= value <= 1000000000) and date is in the format YYYY-MM-DD. All dates are valid calendar dates between the years 2000 and 2100 inclusive.Print a single value: the average number of distinct shifts logged by each active volunteer over the 30-day window ending on (and including) the audit end date and beginning 29 days earlier (inclusive) -- rounded to exactly two decimal places using round-half-up rounding. If there are no active volunteers, print 0.00.
Example 1
Input
2019-07-27 14 1 1 2019-07-20 1 1 2019-07-20 1 1 2019-07-20 2 4 2019-07-20 2 4 2019-07-21 2 4 2019-07-21 3 2 2019-07-21 3 2 2019-07-21 3 2 2019-07-21 3 5 2019-07-21 3 5 2019-07-21 3 5 2019-07-21 4 3 2019-06-25 4 3 2019-06-25
Expected
1.33
Explanation
The audit window is 2019-06-28 through 2019-07-27 (30 days ending 2019-07-27). Volunteer 4's only entries are on 2019-06-25, which is before the window, so volunteer 4 is not active. Volunteer 1 has entries only for shift 1 (1 distinct shift). Volunteer 2 has entries only for shift 4 (1 distinct shift). Volunteer 3 has entries for shifts 2 and 5 (2 distinct shifts). The average over the 3 active volunteers is (1 + 1 + 2) / 3 = 1.333..., which rounds to 1.33.
Example 2
Input
2020-01-01 1 5 10 2019-01-01
Expected
0.00
Explanation
The audit window is 2019-12-03 through 2020-01-01. The only log entry is dated 2019-01-01, which falls well outside the window, so there are zero active volunteers. The output is 0.00.
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 →