Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sorting Without Built-Ins

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

Your question is Sorting Without Built-Ins. 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

Arcadis Digital Twin pipelines may receive measurement values in arbitrary order. Implement a function that returns the values in ascending order without using Python's built-in sort() or sorted() functions.

Use a comparison-based algorithm with O(n log n) worst-case time complexity. The result must be stable, meaning equal values retain their original relative order. Since the input contains integers, stability does not change the visible output, but your merge logic should preserve it.

Formal Specification

  • Input: nums, a list of integers.
  • Output: A new list containing the same values as nums, sorted in nondecreasing order.
  • Do not modify the original input list.
  • Do not use built-in sorting functions or external libraries.

Constraints

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

Function Signature

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