Duplicate Elements in Array

You are provided with an array or list called ARR, consisting of N integers. These integers fall within the range from 0 to N - 1. Some elements in this array may appear more than once. Your task is to identify all such duplicate elements within the array.

Input:

 - The first line contains an integer T, representing the number of test cases.
 - For each test case, the first line includes an integer N, indicating the size of the array.
 - The second line for each test case consists of N space-separated integers representing the array elements.

Output:

 - For each test case, output a line containing K space-separated integers, which are the duplicate elements found in the array.

Example:

Input:
2
5
1 3 1 3 4
6
0 1 2 3 4 5
Output:
1 3

Explanation:

In the first test case, the numbers 1 and 3 appear twice. In the second test case, all numbers are unique, so no duplicates are output, resulting in an empty line.

Constraints:

  • 1 <= T <= 102
  • 1 <= N <= 104
  • 0 <= ARR[i] <= N - 1
  • Time Limit: 1 sec

Note:

  • All elements are within the range 0 to N - 1.
  • Elements may not appear in sorted order.
  • You may return duplicates in any order.
  • If no duplicates exist, return an empty array.
Be the first one to answer
Add answer anonymously...
Directi 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