FastPrepMerge 2 Arrays
Problems/Merge 2 Arrays

Merge 2 Arrays

IBM logoIBM● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Given two sorted arrays, merge them to form a single, sorted array with all items in non-decreasing order.

Function

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

Complete the function mergeArrays in the editor below.

mergeArrays has the following parameter(s):

  1. int a[n]: a sorted array of integers
  2. int b[n]: a sorted array of integers

Returns int[n]: an array of all the elements from both input arrays in non-decreasing order

Examples

Example 1

a = [1, 2, 3]b = [2, 5, 5]return = [1, 2, 2, 3, 5, 5]
Example 1 illustration

Merge the arrays to create array c as follows: a[0] < b[0] -> c = [a[0]] = [1] a[1] < b[0] -> c = [a[0], b[0]] = [1, 2] a[1] < b[1] -> c = [a[0], b[0], a[1]] = [1, 2, 2] a[2] < b[1] -> c = [a[0], b[0], a[1], a[2]] = [1, 2, 2, 3] No more elements in a -> c = [a[0], b[0], a[1], a[2], b[1], b[2]] = [1, 2, 2, 3, 5, 5] Elements were alternately taken from the arrays in the order given, maintaining precedence.

Constraints

  • 1 < n <= 10^5
  • 0 <= a[i], b[i] <= 10^9 where 0 <= i < n

More IBM interview questions

  • Missing IntervalsOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Meandering ArrayVerisk · OA
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
  • Get Maximum PairsAmazon · OA
  • Merge 2 ArraysOracle · OAOracle interview questions
  • Find Maximum GreatnessTwilio · OATwilio interview questions
  • Merge Sorted ArrayAtlassian · OAAtlassian interview questions
  • Binge WatchingVanguard · OAVanguard interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int[] mergeArrays(int[] a, int[] b) {
    // write your code here
    }

}
Checking account…