Reverse Nodes in k-Group Visualizer & Solution | Rulcode
Loading problem details...
192. Reverse Nodes in k-Group
Hard
Topics
Companies
Hint
Understand Before Coding
Visualize This Problem
Open Visualizer
Draw Your Approach
Draw
Example 1:
Input:head = [1,2,3,4,5], k = 2
Output:[2,1,4,3,5]
Explanation:The first 2 nodes (1,2) reverse to (2,1). The next 2 nodes (3,4) reverse to (4,3). Node 5 is left as is because it's a partial group. The final list is 2->1->4->3->5.
Example 2:
Input:head = [1,2,3,4,5], k = 3
Output:[3,2,1,4,5]
Explanation:The first 3 nodes (1,2,3) reverse to (3,2,1). Nodes 4 and 5 are left as is because there are fewer than k=3 nodes remaining. The final list is 3->2->1->4->5.