Show problems as
Classic problem #86MediumLinked ListTwo Pointers

Partition List

Real-world version: Retether the Sensor Pods
Tracked in this browser only
Read Partition List on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Learn the pattern firstDummy Node Technique · Linked List, animated step by step

A survey tether carries a single file of sensor pods, each pod clipped to the one before it. The tether reaches you as pods, the list of calibration offsets in hanging order with the anchor end first, so pods[0] is the pod clipped to the anchor. Offsets may be negative. You are also given an integer threshold.

Re-clip the file so that every pod whose offset is below threshold ends up closer to the anchor than every pod whose offset is threshold or more. Inside each of those two stretches the pods keep the order they hung in when the tether arrived.

Work by unclipping whole pods and clipping them back on: an offset is never edited, and pods are not put in order by offset value. Return the offsets of the re-clipped tether in hanging order, anchor end first. The tether may arrive with no pods on it, in which case the answer is an empty list.

Examples

Example 1

Input
pods = [3, 9, 1, 7, 2], threshold = 5
Output
[3, 1, 2, 9, 7]

Offsets 3, 1 and 2 are below 5, and they reach the anchor end still in that order. Offsets 9 and 7 are 5 or more and follow behind them, also in the order they arrived.

Example 2

Input
pods = [6, 3, 8, 3, 9, 1], threshold = 4
Output
[3, 3, 1, 6, 8, 9]

The below-threshold pods 3, 3 and 1 come first in their arrival order, then 6, 8 and 9 in theirs. Two pods share the offset 3 and both are kept.

Example 3

Input
pods = [], threshold = 0
Output
[]

The tether arrived with no pods clipped to it, so there is nothing to re-clip.

Constraints

  • 0 <= pods.length <= 200
  • -100 <= pods[i] <= 100
  • -200 <= threshold <= 200

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def retether_pods(pods: list[int], threshold: int) -> list[int]:
Java
public int[] retetherPods(int[] pods, int threshold)