All problems
0216MediumArrayDivide and ConquerSortingHeap (Priority Queue)Merge SortBucket SortRadix SortCounting Sort

Tool Offset Ordering

Tracked in this browser only
Write code

Trains the technique from

LeetCode 912Sort an Array

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A machine shop fills in a card for every finishing pass it runs. Each card carries one signed offset in microns: negative when the pass left the part under the nominal size, positive when it left the part over.

You are given offsets, the figures in the order the cards were filed. Return the same figures rearranged from lowest to highest. Every card keeps its own entry, so a figure filed three times has to appear three times in what you return.

Arrange the figures yourself: do not call a library sorting routine or ordering helper. Your routine must run in O(n log n) time and use as little extra room as you can manage.

Examples

Example 1

Input
offsets = [12, -4, 12, 0, -4]
Output
[-4, -4, 0, 12, 12]

Both -4 cards and both 12 cards survive, so the answer holds five figures rising from -4 to 12.

Example 2

Input
offsets = [7, 3, 9, 1, 8, 2, 6]
Output
[1, 2, 3, 6, 7, 8, 9]

The seven figures are all different, so each one lands in its own place in the rising run.

Example 3

Input
offsets = [42]
Output
[42]

A single card is already in order on its own.

Constraints

  • 1 <= offsets.length <= 5 * 10^4
  • -5 * 10^4 <= offsets[i] <= 5 * 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def tool_offset_ordering(offsets: list[int]) -> list[int]:
Java
public int[] toolOffsetOrdering(int[] offsets)
September 7
Apply