KatInterview

Combine and Sort Two Unordered Integer Sequences

Heaps, Sorting & SearchAuto-graded · 21 test cases
EasyAuto-gradedHeaps, Sorting & Searchsortingarraysfundamentals

Last updated

Merge two unordered arrays of integers into a single list arranged in non-decreasing order.

Given two lists of integers, a and k (note: these represent two input integer sequences), write a function that merges all values from both lists into a single list sorted in non-decreasing order.

Each integer in either input array must appear in the output with its original frequency.

Constraints

  • $0 \le \text{len}(a), \text{len}(k) \le 10^5$
  • $-10^9 \le a[i], k[j] \le 10^9$

Examples

Example 1

Input: combine_and_sort([4, 1, 7], [3, 2])

Output: [1, 2, 3, 4, 7]

Example 2

Input: combine_and_sort([], [5, -1, 5])

Output: [-1, 5, 5]

Example 3

Input: combine_and_sort([1, 2, 3], [4, 5])

Output: [1, 2, 3, 4, 5]

Hints

Hint 1

Concatenate the elements from both input lists into a single collection.

Hint 2

Apply a standard sorting algorithm to arrange the combined elements in ascending order.