Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Array Sorting

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

Your question is Python Array Sorting. 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

Motorola Solutions CommandCentral receives alert priorities that must be ordered before they are displayed or processed. Implement a stable merge sort that returns the priorities in ascending order without using Python's built-in sort() or sorted() functions.

Formal Specification

Write sort_priorities(priorities), where priorities is a list of integers. Return a new list containing the same values in nondecreasing order. The input list must not be modified. Duplicate values must be preserved, and the algorithm must remain stable if equal-priority records are later extended with metadata.

Constraints

  • 0 <= len(priorities) <= 10^5
  • -10^9 <= priorities[i] <= 10^9
  • Do not call sort() or sorted().
  • Return a new list and leave priorities unchanged.
  • Target O(n log n) time complexity.

Function Signature

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