Katkat

Merge Sorted Arrays In Place

VerkadaSoftware Engineer · Technical Screen

Last updated

This question evaluates array manipulation and in-place merging skills, specifically understanding sorted sequences, pointer/index management, and space-time trade-offs within array algorithms, and it falls under the Coding & Algorithms domain.

You are given two non-decreasing integer arrays.

  • A has length m + n.
  • The first m elements of A are valid sorted numbers.
  • The last n elements of A are empty placeholders and should not be treated as real values.
  • B has length n and all of its elements are sorted.

Merge all elements from B into A so that after the operation, A contains all m + n elements in non-decreasing order.

Requirements:

  • Modify A in place.
  • Use O(1) extra space.