Question
Given an array of size n containing numbers in the range of long data type, find out all the duplicates in the array.
Sample Input 0
[2, 3011, 4, 2, 1, 5, 3011, 8000]
Output should be 2 and 3011.
Is it possible to find the frequency of repeating elements? How if possible?
Expected time - O(n)
Expected space - O(1)
Similar problems
https://leetcode.com/problems/find-all-duplicates-in-an-array/
P.S. - I solved in 2 ways.
1st method - O(n) time complexity and O(n) space complexity
2nd method - O(nlogn) time complexity and O(1) space complexity
These complexities were not able to satisfy the interviewer. It needed to be more optimized.