Reverse Nodes in k-Group
Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

30:00

Reverse Nodes in k-Group
hard
Topics
Companies

Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.

Example 1:
Input: {"head":[1,2,3,4,5],"k":2}
Output: [2,1,4,3,5]
Constraints:
  • The number of nodes is nn.

  • 1kn50001 \leq k \leq n \leq 5000

  • 0Node.val10000 \leq \text{Node.val} \leq 1000

Input
arr ={"head":[1,2,3,4,5],"k":2}

Start

groupPrev

0

1

2

3

4

5

NULL
Variables
No variables to display
DepthFunction Call
Stack empty
0/11