Partition List
Updated
Problem statement
You are given the head of a singly linked list and an integer x. Reorder the existing nodes so that every node with a value less than x comes before every node with a value greater than or equal to x.
This splits the list into two groups. Inside each group, keep the nodes in the same order they had in the original list. Return the head of the reordered list.
Function
partitionList(head: ListNode, x: int) → ListNodeExamples
Example 1
head = [1,4,3,2,5,2]x = 3return = [1,2,2,4,3,5]Moved or new
The nodes with values below 3 are 1,2,2, in their original order. The other nodes are 4,3,5, also in their original order. Putting the first group before the second group gives the answer.
Example 2
head = [2,1]x = 2return = [1,2]Moved or new
Only node 1 has a value less than x, so it moves to the front. The other node comes after it, which gives the answer.
Example 3
head = []x = 0return = []An empty list remains empty.
Constraints
- The list contains at most
200nodes. -100 <= Node.val <= 100.-100 <= x <= 100.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Remove Nth Node From End of ListDruva · ONSITE INTERVIEW
- Find the Entry of a Linked List CycleQualys · ONSITE INTERVIEWQualys interview questions
- Detect a Linked-List CyclePaytm · ONSITE INTERVIEWPaytm interview questions
- Detect a Linked-List CycleCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Rearrange a Linked List from Alternating EndsConcentric AI · ONSITE INTERVIEWConcentric AI interview questions
- Palindrome Linked List with RestorationMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Linked List Cycle Entry NodeGoogle · ONSITE INTERVIEWGoogle interview questions
- Detect and Break a Linked-List CycleAmazon · ONSITE INTERVIEW
- Find the Entry of a Linked List CyclePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Remove a Cycle from a Singly Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions