A community garden keeps a single shared sign-in sheet: every time a gardener visits, they jot down their gardener id and the exact date and time of that visit. At the end of each season the garden committee wants to know, for every gardener who signed in at all during the year 2020, the exact timestamp of that gardener's single most recent 2020 visit -- so they know who to invite back first for the next planting kickoff.
n, the number of sign-in entries.n lines contains three space-separated tokens: an integer gardener_id, a date in YYYY-MM-DD format, and a time in HH:MM:SS format (24-hour clock), describing one sign-in event. Together the date and time always form a valid calendar timestamp.For every gardener_id that has at least one sign-in entry whose date falls in the year 2020, print one line gardener_id date time giving the date and time of that gardener's latest (most recent) 2020 sign-in. Print the lines in ascending order of gardener_id. Gardeners with no sign-in entry in 2020 must not be printed at all. If no gardener qualifies, print nothing.
1 <= n <= 1000001 <= gardener_id <= 10^92000 and 2100 inclusive, and the date/time always describes a valid calendar timestamp (leap years handled correctly).Example 1
Input
5 1 2020-06-30 15:06:07 1 2020-07-27 13:04:22 2 2020-03-01 21:00:00 2 2020-01-06 05:22:35 4 2020-06-25 15:37:14
Expected
1 2020-07-27 13:04:22 2 2020-03-01 21:00:00 4 2020-06-25 15:37:14
Explanation
Gardener 1 has two 2020 entries; the later one is 2020-07-27 13:04:22. Gardener 2 has two 2020 entries; the later one is 2020-03-01 21:00:00. Gardener 4 has a single 2020 entry, 2020-06-25 15:37:14, which is trivially its own latest. All three gardeners qualify, printed in ascending id order.
Example 2
Input
3 1 2019-05-05 10:00:00 2 2020-08-08 08:08:08 3 2021-01-01 01:01:01
Expected
2 2020-08-08 08:08:08
Explanation
Gardener 1's only entry is dated 2019, so gardener 1 does not qualify. Gardener 3's only entry is dated 2021, so gardener 3 does not qualify either. Only gardener 2's entry falls in 2020, so the output has a single line for gardener 2 with that exact timestamp.
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 →