31: Find array duplicates

Given an array of integers, from 1 to array.Length inclusive. Some array items appear twice and others appear once. Find all duplicates. The result should be in ascending order

Note: Solve without extra space and in O(n) runtime

 

Example 1

Input: [3, 2, 1, 3]

Output: [3]

Example 2

Input: [3, 2, 1, 3, 2]

Output: [2, 3]
Difficulty:Medium
Topic:Array
Problem #:31