Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sorting Algorithm Implementation

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

Your question is Sorting Algorithm Implementation. 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

A Cirrus Logic audio validation pipeline produces measurements from codec tests. Each measurement is a dictionary with a latency_us integer and a test_id string. Implement a stable sorting algorithm that returns the measurements in ascending order of latency_us without using Python's built-in sorting functions.

If two measurements have the same latency, preserve their original relative order. The input list must not be modified.

Formal Specification

Implement sort_measurements(measurements), where measurements is a list of dictionaries containing:

  • latency_us: an integer latency value
  • test_id: a string identifier

Return a new list containing the same dictionaries, ordered by increasing latency_us. A merge sort is expected because it provides predictable O(n log n) time and demonstrates how to preserve stability.

Constraints

  • 0 <= len(measurements) <= 10^5
  • -10^9 <= measurements[i]["latency_us"] <= 10^9
  • Every measurement contains valid "test_id" and "latency_us" fields
  • Do not call sorted() or .sort()
  • The input list must remain unchanged

Function Signature

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