Problem Challenge 1

Reverse alternating K-element Sub-list (medium) #

Given the head of a LinkedList and a number ‘k’, reverse every alternating ‘k’ sized sub-list starting from the head.

If, in the end, you are left with a sub-list with less than ‘k’ elements, reverse it too.

Created with Fabric.js 1.6.0-rc.1 Original List: Example: head head 1 2 3 4 5 6 7 8 null Reversed Sub-list: k=2 2 1 3 4 6 5 7 8 null

Try it yourself #

Try solving this question here:

Output

0.724s

Nodes of original LinkedList are: 1 2 3 4 5 6 7 8 Nodes of reversed LinkedList are: 1 2 3 4 5 6 7 8

Mark as Completed
←    Back
Reverse every K-element Sub-list (medium)
Next    →
Solution Review: Problem Challenge 1