Dsa
Linked List
Medium
The K-Group Pivot
Given a linked list and an integer K, process the list in contiguous blocks of size K. For each block, find the maximum and minimum values. Move the maximum value to the very beginning of the block and the minimum value to the very end of the block. If there are multiple occurrences, use the first encountered for max and the last encountered for min. Other elements in the block must maintain their original relative order. If the last block is smaller than K, treat it as a full block.
Example:
Input: K=3, List: 1 5 2 4 0 3
- Block 1 [1, 5, 2]: Max 5, Min 1. Result: [5, 2, 1]
- Block 2 [4, 0, 3]: Max 4, Min 0. Result: [4, 3, 0]
Output: 5 2 1 4 3 0
Key concepts
linked_listreorderingmath
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