Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Algorithm: Sort Numbers

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

Your question is Algorithm: Sort Numbers. 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

Royal Cyber engineering services may need to normalize numeric values before processing them. Given an array of integers, return a new array containing the same values in ascending order.

Implement the algorithm without using Python's built-in sort() or sorted() functions. The input array may contain duplicate values, negative numbers, and zero. The original array should not be modified.

Formal Specification

Implement sort_numbers(nums), where nums is a list of integers. Return a new list containing all values from nums in nondecreasing order.

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • Do not call sort() or sorted().
  • The input list must remain unchanged.

Function Signature

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