# Reverse Nodes II

LINKED LIST

### Problem

Given a linked list `head`

, reverse the nodes of the list `k`

at a time and return its modified list. `k`

is a positive integer and is less than or equal to the length of the linked list.

If the number of nodes is not a multiple of `k`

then left-out nodes, in the end, should remain as it is. You may not alter the values in the list's nodes, only nodes themselves may be changed.

### Examples

`// Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 reverseKGroup([1,2,3,4,5,6], 3) // returns [3,2,1,6,5,4] // The list [1,2,3,4,5,6] is modified by reversing // every 3 nodes: [3,2,1] and [6,5,4]`

Loading...

1

2

3

4

5

6