I have 2 arrays (A and B) that contain similar data with some differences. I would like to return an array of objects that are only in A and another array of objects that are only in B. So far I have been thinking:
- Brute force with some optimizations (this is trivial)
- Sort the arrays and use a binary search.
What are my other options? Any languages/solutions are fair game.
You could sort both arrays then do a linear scan through both arrays at the same time. This would be an O(nlogn) algorithm for the sort and O(n) for the scan / building of the new arrays.