Reverse Link List 1 ,2 ,3 ,4 5 but Limited by Group Number

Assume Link List is 1, 2, 3, 4, 5. Reverse Link List but Limited by
Group Number.
The output might be like this.

When Group Number = 2
2->1->4->3->5

When Group Number =3
3->2->1->5->4