Given an array of n integers where every value is between 1 and n and each value appears once or twice, return every value that appears twice, using only O(1) extra space beyond the output.
Example 1
Explanation: 2 and 3 each appear twice in the array; every other value from 1-8 appears exactly once.
Example 2
Explanation: Only 1 is repeated.
Example 3
Explanation: No value repeats, so no duplicates are reported.
How would you restore the input array to its original values after collecting the duplicates, and why might a caller want that?
Code execution is coming soon.