BackmediumLinked Lists linked-lists medium

Partitioned Linked List Reordering Solution

Problem Statement

Given a linked list where each node contains an integer `value` and an integer `priority`, reorder the linked list such that all nodes with `priority` greater than a given threshold are moved to the front of the list, while maintaining their original order, and the remaining nodes are appended at the end in their original sequence.

Example 1
Input
[{id: 1, speed: 80}, {id: 2, speed: 90}, {id: 3, speed: 70}]
Output
[{id: 2, speed: 90}, {id: 1, speed: 80}, {id: 3, speed: 70}]

Explanation: Node with id 2 has speed greater than 87, so it is moved to the front.

Constraints

  • 1 <= number of nodes <= 10^5
  • -10^5 <= value <= 10^5
  • 0 <= priority <= 100
  • The threshold is given as an input to the function
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free