MediumArraysNot started

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
 JavaScript · reference solution
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

Your program
const seen = new Set();
let answer = 'NONE';
for (const id of readline().split(' ')) {
  // Stop at the first ID already in seen.
}
console.log(answer);

Tests: 3 cases including the examples. Passing every test marks the exercise solved in this browser.

Ready for a challenge?

How this page was checked. Every program on it was run with Node.js 22 at build time; runs in your browser in an isolated Web Worker by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.