Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sort Array Without Builtins

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Sort Array Without Builtins. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Globallogic QA automation may need deterministic ordering of numeric test data without relying on Python's built-in sorting implementation. Implement a stable merge sort that returns the values in nondecreasing order.

Your function must not call sort(), sorted(), or any library sorting helper. The original input list must remain unchanged. Duplicate values must be preserved, and the algorithm should meet the required O(n log n) time bound.

Formal Specification

  • Input: nums, a Python list of integers.
  • Output: A new Python list containing every value from nums in nondecreasing order.
  • Stability: Equal values must retain their original relative order. Since the input contains integers only, this means duplicates must appear the same number of times.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • The original input list must not be modified
  • Do not use sort(), sorted(), or external sorting utilities

Function Signature

def merge_sort(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output