Merge two sorted arrays

What is the time complexity of merging two sorted arrays of sizes mm and nn into a single sorted array?

Show hints (2)+
  1. The inputs are already sorted — no re-sorting needed.
  2. Each element is visited once by a pointer.

Answer

Reveal answer →

$O(m + n)$

Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.

Asked at: Optiver, IMC

Related questions