Hi all,
The task here is to get the duplicate numbers that a list contains. Let's assume that the list can be huge. Example:
Input array: I = { 12, 24, 2, 19, 12, 6, 2, 2, ... n}
Output array: O = {12, 2, ...}
One solution that leaps to my mind is:
The time complexity for the above is n ^ 2.
Any other/better way to do this? Let's just have the algorithm without using predefined data structures (like Set (in Java)).
Regards,
Ven.
The task here is to get the duplicate numbers that a list contains. Let's assume that the list can be huge. Example:
Input array: I = { 12, 24, 2, 19, 12, 6, 2, 2, ... n}
Output array: O = {12, 2, ...}
One solution that leaps to my mind is:
- take each element from I
- compare that with all the elements in I in a nested loop
- if match found, put the element in O
The time complexity for the above is n ^ 2.
Any other/better way to do this? Let's just have the algorithm without using predefined data structures (like Set (in Java)).
Regards,
Ven.