
Asked in Housing.com
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.
Be the first one to answer
Add answer anonymously...
Top Software Engineer Interview Questions Asked at Housing.com
Q. Given a BST where two nodes have been swapped, violating the BST property, find ...read more
Q. Design a system for Bookmyshow.com. When seats are booked, they must be locked u...read more
Q. Given a set of n steps, a person can climb one or two steps at a time. Find the ...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for Housing.com Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

