Rangers maintain a network of motion-triggered trail cameras across a nature reserve. Each time a tagged animal trips a camera, the sighting is logged as the animal's tag ID together with the calendar date of the capture. An animal is treated as a likely resident of the study area if it was captured by any camera(s) twice within a seven-day window — that is, there exist two of its logged sighting dates whose difference is at most 7 days (the two sightings may even fall on the exact same date). Given the full sighting log, report every animal's tag ID that qualifies.
tagID YYYY-MM-DD.Print the qualifying tag IDs (animals with at least two sightings whose dates are at most 7 days apart), one per line, in ascending lexicographic order, with no duplicates. If no animal qualifies, print nothing.
Example 1
Input
5 A1 2024-01-01 A1 2024-01-10 B2 2024-03-05 B2 2024-03-06 C3 2024-05-01
Expected
B2
Explanation
A1's two sightings are 9 days apart (> 7), so A1 does not qualify. B2's two sightings are 1 day apart (<= 7), so B2 qualifies. C3 has only one sighting, so it cannot qualify. Only B2 is printed.
Example 2
Input
4 X 2024-06-01 X 2024-06-08 Y 2024-06-01 Y 2024-06-09
Expected
X
Explanation
X's sightings are exactly 7 days apart (June 1 to June 8), which satisfies the inclusive 'at most 7 days' rule, so X qualifies. Y's sightings are 8 days apart, which exceeds the limit, so Y does not qualify. Only X is printed.
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 →