A warehouse's overhead scanner logs the tag code printed on every pallet as it passes beneath it, producing a sequence of n tag codes in the exact order they were scanned during a shift. A tag code is called singleton for the shift if it was scanned on exactly one pallet all day (it appears exactly once in the sequence). Considering only the singleton tag codes, in the order their single occurrence appears in the scan log, find the k-th singleton tag code. If the shift produced fewer than k singleton tag codes, report an empty result instead.
n and k.n space-separated tag codes (strings of lowercase English letters).A single line containing the k-th singleton tag code in scan order, or an empty line if fewer than k singleton tag codes exist.
1 <= n <= 10001 <= k <= n1 and 10 and consists only of lowercase English letters a-z.Example 1
Input
6 2 d b c b c a
Expected
a
Explanation
The codes b and c each appear twice, so they are not singletons. Only d and a appear exactly once, in that scan order, so the 1st singleton is d and the 2nd singleton is a — the answer is a.
Example 2
Input
3 1 aaa aa a
Expected
aaa
Explanation
All three codes ("aaa", "aa", "a") are distinct strings, so each appears exactly once and each is a singleton. The 1st singleton in scan order is "aaa".
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 →