Two remote camera traps -- one covering the North bank and one covering the South bank of a river crossing -- silently record wildlife activity through the night. Every time an animal triggers a trap, the trap appends that animal's species code (a short lowercase-letter identifier) to its own log for the night; a species that never triggers a given trap simply never appears in that trap's log, and one that triggers a trap several times appears that many times (possibly scattered) through the log. Rangers only trust a sighting when it is unambiguous on both sides of the crossing: a species code counts as a clean single sighting for the night if and only if it appears in the North Camera's log exactly once and in the South Camera's log exactly once. Given both logs for one night, report how many distinct species codes qualify as clean single sightings.
n, the number of entries in the North Camera log.n space-separated lowercase strings, the North Camera log entries in the order they were recorded.m, the number of entries in the South Camera log.m space-separated lowercase strings, the South Camera log entries in the order they were recorded.A single integer: the number of distinct species codes that appear exactly once in the North Camera log and exactly once in the South Camera log.
Example 1
Input
4 owl otter owl fox 3 otter fox fox
Expected
1
Explanation
North log counts: owl=2, otter=1, fox=1. South log counts: otter=1, fox=2. "otter" appears exactly once in both logs, so it qualifies. "fox" appears once in the North log but twice in the South log, so it is disqualified. "owl" appears twice in the North log, so it is disqualified regardless of the South log. Only "otter" qualifies, so the answer is 1.
Example 2
Input
3 lynx wolf lynx 2 wolf moose
Expected
1
Explanation
North log counts: lynx=2, wolf=1. South log counts: wolf=1, moose=1. "wolf" appears exactly once in both logs, so it qualifies. "lynx" appears twice in the North log, so it is disqualified. "moose" never appears in the North log at all, so it is disqualified. Only "wolf" qualifies, so the answer is 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 →