FastPrepImplement Merge Sort
Problems/Implement Merge Sort

Implement Merge Sort

Salesforce logoSalesforce● MediumNEW GRADONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report explicitly asks for merge sort from scratch and discussion of its recursion tree.

Given an integer array nums, return a new array containing the same values in nondecreasing order.

Implement merge sort: recursively split the range, sort both halves, and merge the sorted halves.

Function

mergeSort(nums: int[]) → int[]

Examples

Example 1

nums = [5,2,3,1]return = [1,2,3,5]

The two sorted halves merge into nondecreasing order.

Example 2

nums = [5,1,1,2,0,0]return = [0,0,1,1,2,5]

Duplicate values are retained.

Constraints

  • 0 <= nums.length <= 100000
  • -1000000000 <= nums[i] <= 1000000000

More Salesforce Onsite Interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
  • Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
  • K Largest Elements with QuickselectAMD · ONSITE INTERVIEWAMD interview questions
  • Sort an ArrayBank of America · ONSITE INTERVIEWBank of America interview questions
  • Generalized N-SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Implement QuicksortByteDance · PHONE SCREENByteDance interview questions
  • Count InversionsExpedia · OAExpedia interview questions
  • Count InversionsNutanix · OANutanix interview questions
  • Closest Pair of PointsCitadel · PHONE SCREENCitadel interview questions
  • Temporal AnomaliesInMobi · OAInMobi interview questions
  • Minimum Euclidean Distance Between PointsLuma AI · OALuma AI interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int[] mergeSort(int[] nums) {
        // Write your code here
    }
}
Checking account…