Reverse Nodes in Even Length Groups
Try to solve the Reverse Nodes in Even Length Groups problem.
We'll cover the following
Statement
Given the head of a linked list, the nodes in it are assigned to each group in a sequential manner. The length of these groups follows the sequence of natural numbers. Natural numbers are positive whole numbers denoted by
In other words:
The
node is assigned to the first group. The
and nodes are assigned to the second group. The
, , and nodes are assigned to the third group, and so on.
Your task is to reverse the nodes in each group with an even number of nodes and return the head of the modified linked list.
Note: The length of the last group may be less than or equal to 1 + the length of the second to the last group.
Constraints:
Number of nodes
Examples
You can understand the problem a little better with the help of the illustration below:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy