First repeated ticket
A scanner records ticket IDs in arrival order. Print the ID at the first repeated scan, or NONE when all IDs are unique. This is not the smallest repeated ID: the second appearance that occurs earliest wins. Ticket IDs are case-sensitive.
Input
One line of space-separated ticket IDs.
Output
One ID or NONE.
Example 1
Input
b a a b
Output
a
The second a appears before the second b, so a is the first repeated scan even though b appeared first.
Constraints
- The scan line contains 1 to 200 IDs.
- Ticket IDs are case-sensitive non-empty tokens.
Hints
Hint 1 of 2
A Set supports fast membership checks.
Hint 2 of 2
Walk input order and stop immediately when a repeated ID appears.
Solution
Show a reference solution and explanation
const seen = new Set();
let answer = 'NONE';
for (const id of readline().split(' ')) {
if (seen.has(id)) { answer = id; break; }
seen.add(id);
}
console.log(answer);
Why it works
The first time an ID enters the Set is not a duplicate; the next occurrence is. Returning at the first duplicate event preserves arrival order, unlike sorting or counting all IDs before choosing an answer.
Lesson for this exercise: JavaScript Arrays: Creating, Indexing and Changing Lists