Find Duplicate in Array Problem Statement

You are provided with an array of integers 'ARR' consisting of 'N' elements. Each integer is within the range [1, N-1], and the array contains exactly one duplicated element.

Your task is to identify the duplicated element.

Example:

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

The element 3 occurs more than once, hence it is the duplicate.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 105
  • 1 <= ARR[i] <= N - 1
  • Time Limit: 1 sec
Input:
The first line of input contains an integer ‘T’ representing the number of test cases. 
For each test case, the first line includes an integer ‘N’ for the number of elements in the array.
The following line for each test case contains ‘N’ space-separated integers representing elements of the array.
Output:
For each test case, print the duplicate element in the array.
Each test case's result should be on a new line.
Note:
You are not required to print anything, as that's handled already. Your task is to implement the function to return the answer.
AnswerBot
1y

The task is to find the duplicate element in an array of integers.

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

  • Return the element with a frequency greater...read more

Help your peers!
Select
Add answer anonymously...

Unthinkable Solutions Software Developer interview questions & answers

A Software Developer was asked 9mo agoQ. Given an array of intervals where intervals[i] = [starti, endi], merge all overl...read more
A Software Developer was asked 8mo agoQ. Implement debouncing, create a nodejs server with a get / post api, a puzzle, ja...read more
A Software Developer was asked 8mo agoQ. Designing dbms for a college website

Popular interview questions of Software Developer

A Software Developer was asked 9mo agoQ1. Given an array of intervals where intervals[i] = [starti, endi], merge all overl...read more
A Software Developer was asked 7mo agoQ2. Implement debouncing, create a nodejs server with a get / post api, a puzzle, ja...read more
A Software Developer was asked 7mo agoQ3. Designing dbms for a college website
Unthinkable Solutions 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