Question bank › Linked List
Dsa Linked List Hard

Rearrange Linked List

Given a linked list, rearrange it such that all nodes with values less than a value x come before nodes with values greater than or equal to x. The original relative order of the nodes in each partition should be preserved. Input Format: - The first line contains the integer n, the number of nodes in the linked list. - The second line contains n integers, representing the values of the nodes. - The third line contains the integer x. Output Format: - Print the rearranged linked list in a single line, with elements separated by spaces. Example: Input: 5 3 5 8 5 10 5 Output: 3 5 5 8 10

Key concepts

linked_listrearrangementpartitioning

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.