You are given a linked list. Group its nodes into consecutive groups whose sizes follow the natural number sequence 1, 2, 3, 4, ... (the last group may be smaller, taking whatever nodes remain). Reverse the nodes within each group whose actual length is even; leave odd-length groups unchanged. The list is given as an array; return the resulting array.
Input: An array of node values.
Output: Array — the modified list.
Input: [5,2,6,3,9,1,7,3,8,4]
Output: [5,6,2,3,9,1,4,8,3,7]
Explanation: Groups [5],[2,6],[3,9,1],[7,3,8,4]; even-length ones reversed.Input: [1,1,0,6]
Output: [1,0,1,6]
Explanation: Second group [1,0] reversed; last group [6] odd.Input: [1]
Output: [1]
Explanation: Single node.1<=n<=10^50<=value<=10^5