Find All Duplicates in an Array
January 6, 2024
Problem # Given an array of integers, where each element appears either once or twice, find all elements that appear twice in the array. The solution should achieve O(n) time complexity and O(1) extra space. Example: Input: [4,3,2,7,8,2,3,1] Output: [2,3] Explanation: The numbers 2 and 3 appear twice in the array. Input: [1,1,2] Output: [1] Explanation: The number 1 appears twice. Solution Approach # The solution involves using the array itself for hashing by marking visited numbers. ...