Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sort Map and Partition Array

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

Your question is Sort Map and Partition Array. 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

HCL Digital Experience configuration tools may receive unordered settings and signed priority adjustments. Implement a function that sorts a map by its numeric values and orders an integer array so negative values appear first, followed by zeros and positive values, with each group in increasing order.

Formal Specification

Implement sort_map_and_array(mapping, nums):

  1. mapping is a Python dictionary whose keys are strings and whose values are integers. Return a new dictionary ordered by ascending value. If two entries have the same value, order them by ascending key.
  2. nums is a list of integers. Return a new list containing all negative values first, then zero values, then positive values. Values within each group must be in increasing order. The input list must not be modified.
  3. Return a two-element tuple: (sorted_mapping, sorted_nums).

The returned dictionary's iteration order represents the requested map order. Do not rely on input insertion order for the result's ordering.

Constraints

  • 0 <= len(mapping), len(nums) <= 10^5
  • -10^9 <= mapping values, nums[i] <= 10^9
  • Mapping keys are unique strings
  • The input list and dictionary must remain unchanged

Function Signature

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