FastPrepMerge Into the Zero-Padded Array
Problems/Merge Into the Zero-Padded Array

Merge Into the Zero-Padded Array

Adobe logoAdobe● EasyFULLTIMEINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: An Adobe first round had three coding questions, and one of them was an in-place merge of two sorted arrays: the longer array keeps spare places at its end, one for each value of the shorter array. The author solved it with three indices.

The report gives no limits or examples and does not say how real zeros in A are told apart from the room at the end. Here the room is exactly the last B.length places, the function returns A after merging, A has at most 3000 places and values are from -10^5 to 10^5. The examples are our own.

The judged task matches the report at about 90%.

You are given two integer arrays a and b, both sorted from smallest to largest. Let m = b.length. The first a.length - m values of a are its real values; the last m places of a hold 0 and are only room for the values of b.

Merge b into a, so that a holds all real values of both arrays in sorted order, and return a. Try to do it in place, using only a few extra variables. A 0 among the real values (or in b) is a real value like any other.

Function

mergeIntoPadded(a: int[], b: int[]) → int[]

Examples

Example 1

a = [1,4,7,0,0]b = [2,9]return = [1,2,4,7,9]

The first three values of a are real; the two zeros at the end are room for b. Merging 1, 4, 7 with 2, 9 gives 1, 2, 4, 7, 9.

Example 2

a = [0,0,0]b = [-5,0,3]return = [-5,0,3]

a has no real values, only room for 3. The answer is b itself. The 0 in b is a real value.

Example 3

a = [-3,0,6]b = []return = [-3,0,6]

b is empty, so nothing at the end of a is room: here the 0 is a real value and a stays as it is.

Constraints

  • 1 <= a.length <= 3000 and 0 <= b.length <= a.length
  • -10^5 <= a[i], b[i] <= 10^5
  • With m = b.length, the first a.length - m values of a are sorted, its last m values are all 0, and b is sorted.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] mergeIntoPadded(int[] a, int[] b) {
    // Write your code here.
}
Checking account…