My first instinct was to just concat everything and sort, which works but feels lazy for a Meta interview.
Use a min-heap to perform a k-way merge across the three arrays, tracking the last added value to skip duplicates. Alternatively, use three pointers to merge sequentially while deduplicating. Discuss time and space complexity and handle edge cases like empty arrays.
Pro tip: Clarify whether the input arrays can contain duplicates and whether the output must be sorted in ascending order. Also, mention that if the arrays are very large, a heap-based approach is more efficient than merging two at a time.
Ask about input sizes, whether arrays can be empty, if duplicates exist within each array, and if the output should be a new array or in-place. Confirm the expected time/space complexity.
Decide between a heap-based k-way merge (O(N log k) time) or iterative two-array merge (O(N * k) time). Explain the trade-offs and pick the most efficient for the given constraints.
For heap approach: initialize a min-heap with the first element of each non-empty array, along with array index and element index. Repeatedly extract the minimum, add to result if different from last added, and push the next element from the same array. For pointer approach: merge arrays one by one while skipping duplicates.
During merge, compare the current element with the last added element to skip duplicates. Handle empty arrays by ignoring them in the heap or pointer initialization. Ensure the result is sorted and contains no duplicates.
State time complexity: O(N log k) for heap, where N is total elements and k=3; space O(N) for output plus O(k) for heap. Walk through a small example to verify correctness, including duplicates and empty arrays.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.