Practice arena
C++17·2 s·128 MB
LinearFoundation
Frequency table
Scan left to right and return the value whose frequency reaches two first. Return -1 if every value is unique.
Input
- — The first line contains T.
- — Each case contains n followed by n integers.
Output
Print one repeated value or -1 per case.
Technique
unordered_set
Target
O(n) expected
Constraints & sample
- 1 ≤ n ≤ 200,000
- Values fit in a signed 32-bit integer
Sample input
3 7 2 1 3 5 3 2 4 4 1 2 3 4 6 9 9 8 8 7 7
Expected output
3 -1 9
Before you submit
- Test the smallest valid input and one awkward edge case.
- Keep the solution within O(n) expected.
- Match spacing and line breaks exactly before checking 8 hidden cases.
Draft saved locally · 459 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17
Visible testcases
Editable and stored only in this browser. Hidden judge cases never change.
Checking your session…
Run checks Sample · Submit checks 8 hidden cases
Run the sample first, then send your solution through 8 hidden cases.
Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.