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.
AnswerBot
4mo

Identify the duplicate integer in an array containing numbers between 1 and N-1.

  • Iterate through the array and keep track of the frequency of each element using a hashmap.

  • Return the element with a freq...read more

Help your peers!
Select
Add answer anonymously...

Ernst & Young Senior Software Engineer interview questions & answers

A Senior Software Engineer was asked Q. For SSRS reports, why are temporary tables used instead of regular tables?
A Senior Software Engineer was asked Q. How is memory managed in Python?
A Senior Software Engineer was asked 12mo agoQ. Technology used

Popular interview questions of Senior Software Engineer

A Senior Software Engineer was asked Q1. For SSRS reports, why are temporary tables used instead of regular tables?
A Senior Software Engineer was asked Q2. How is memory managed in Python?
A Senior Software Engineer was asked 12mo agoQ3. Technology used
Ernst & Young Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits