Stack Bash - Master data structures and algorithms

Pivot linked list

You're given a linked list that contains numbers, along with a single integer known as a pivot.
Write a function that reorganizes the linked list such that nodes with numbers less than the pivot appear before the nodes with numbers greater than or equal to the pivot.
For example, if your function is given the following linked list and pivot:
linked_list = (1) -> (5) -> (7) -> (2)
pivot = 3
Your function should return the following linked list:
(1) -> (2) -> (5) -> (7)
Note that after partitioning the nodes around the pivot, the order that the nodes appear in the original list should be preserved in the output.

Try it first


8 Essential Linked Lists Coding Interview Problems

Master Linked Lists by trying the coding challenges below.
  1. 1.Insert NodeEasy
  2. 2.Remove NodeEasy
  3. 3.Find the MiddleEasy
  4. 4.Add Linked ListsEasy
  5. 5.Reverse Linked ListMedium
  6. 6.Detect CycleMedium
  7. 7.Merge Linked ListsMedium
  8. 8.Pivot Linked ListHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.