Solution 1 — O(N), but with extra space: use a hash set, traverse the first array, note down the elements. Traverse the second array, and dont emit the elements already in hash set.
Solution 2 — O(N log(N)) : Sort the arrays and then simply use the logic of merge sort.,
1 comment:
Solution 1 — O(N), but with extra space: use a hash set, traverse the first array, note down the elements. Traverse the second array, and dont emit the elements already in hash set.
Solution 2 — O(N log(N)) : Sort the arrays and then simply use the logic of merge sort.,
Post a Comment