Duplicate Integer in Array

Given an array ARR of size N, containing each number between 1 and N-1 at least once, identify the single integer that appears twice.

Input:

The first line contains an integer, 'T', representing the number of test cases.
The first line of each test case contains a single integer, 'N', indicating the array size.
The second line contains 'N' space-separated integers denoting the elements of the array 'ARR'.

Output:

For each test case, return the duplicate number in the array. Output should be a single integer per test case, each on a new line.

Example:

Input:
ARR = [1, 2, 3, 4, 4]
Output:
4
Explanation:

The duplicate integer present in the array is 4.

Constraints:

  • 1 <= T <= 10
  • 2 <= N <= 10^5
  • 1 <= ARR[i] <= N - 1
  • A duplicate number is guaranteed to be present in the array.
  • Time limit: 1 sec.
Be the first one to answer
Add answer anonymously...
SAP Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter