#C10679. Find Duplicates in an Array
Find Duplicates in an Array
Find Duplicates in an Array
You are given an array of n integers where each integer is in the range \(1\) to \(n\) (inclusive). In this array, some elements appear exactly once and others appear exactly twice. Your task is to identify all the elements that appear twice.
Input Constraints:
- \(1 \le n \le 10^5\)
- Every element \(a_i\) satisfies \(1 \le a_i \le n\).
Note: Try to achieve an algorithm that uses constant extra space and runs in \(O(n)\) time.
inputFormat
The first line contains an integer \(n\), representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output the duplicate elements in a single line, separated by a single space. If there is no duplicate, output an empty line.
## sample8
4 3 2 7 8 2 3 1
2 3