The TransCompilator

Solved LeetCode program · 25 of 1,000

#0025 · Reverse Nodes in k-Group

Hard Linked List chunk-01.md

Original English source

The values is a list of 1, 2, 3, 4, and 5. The groupsize is 2. The last is the last position of values. The start is 0.
Repeat while start plus groupsize minus 1 is at most last.
The left is start. The right is start plus groupsize minus 1. Repeat while left is less than right, swap item left of values and item right of values, add 1 to left, subtract 1 from right. Increase start by groupsize.

For each value in values, display value.

Open in Playground Browse all 1,000 problems

Expected stdout

2
1
4
3
5