Find the Duplicate Number

Easy

You are given a list of integers nums of size n+1. Each number in nums lies from 1 to n.
All numbers appear once, except x which appears twice.

Find the number x.

Example 1
nums: [3, 1, 2, 4, 2]
Answer: 2
Example 2
nums: [3, 1, 3, 2]
Answer: 3

Testing

Input Format

The first line contains an integer ‘T’ denoting the number of test cases.

For each test case, the input has two lines:

  • The first line has a positive integer ‘n’.
  • The second line has n+1 space-separated integers denoting the list nums.

Output Format

For each test case, the output has one line containing the value of x.

Sample Input

2
4
3 1 2 4 2
3
3 1 3 2

Expected Output

2
3

Constraints

1 <= T <= 100
1 <= n <= 10000

Editorial Link: Editorial