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...

SAP Software Developer interview questions & answers

A Software Developer was asked 9mo agoQ. Implement a stack using queues.
A Software Developer was asked 9mo agoQ. Write a function that reverses a string.
A Software Developer was asked 10mo agoQ. Implement a stack using other data structures.

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. If you have 1 million requests, how will you manage that?
A Software Developer was asked 9mo agoQ2. Implement a stack using queues.
A Software Developer was asked 9mo agoQ3. Write a function that reverses a string.

Top HR questions asked in SAP Software Developer

A Software Developer was asked 8mo agoQ1. Introduce yourself.
A Software Developer was asked 10mo agoQ2. What is your top priority when choosing a new job?
A Software Developer was asked 10mo agoQ3. Tell me about your current project and the technologies you are using.
SAP Software Developer 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