Matsushita's Blog

Merge two sorted arrays

Problem

You are given two sorted arrays, A and B, where A has large enough buffer at the end to hold B. Write a method to merge B into A in sorted order

How to Solve

By merging two arrays like merge sort, we can achieve the goal. Since A has enough buffer at the end, we traverse the arrays from end to start.