Innovacer | R-1
Summary
I encountered a linked list problem titled 'Reverse in Groups of Increasing Size' during my interview at Innovacer, but I was unable to complete the solution.
Full Experience
Problem: Reverse in Groups of Increasing Size You are given a singly linked list. Reverse the nodes of the list in groups of increasing size: The 1st group has 1 node, The 2nd group has 2 nodes, The 3rd group has 3 nodes, and so on. If the remaining nodes are fewer than the required group size, leave them as they are.
Example 1 Input: 1 β 20 β 3 β 5 β 50 β 2 β 100 β 15 β 9
Process: Group 1 (size=1): [1] β stays as [1]
Group 2 (size=2): [20,3] β reversed to [3, 20]
Group 3 (size=3): [5,50,2] β reversed to [2, 50, 5]
Group 4 (size=4): [100,15,9] β only 3 nodes < 4 β leave as is
Output: 1->3->20->2->50->5->100->15->9
I wasn't able to reach till the end.
Similar too : https://leetcode.com/problems/reverse-nodes-in-k-group/submissions/1884845981/
Interview Questions (1)
Reverse Linked List in Increasing Size Groups
You are given a singly linked list. Reverse the nodes of the list in groups of increasing size: The 1st group has 1 node, The 2nd group has 2 nodes, The 3rd group has 3 nodes, and so on. If the remaining nodes are fewer than the required group size, leave them as they are.
Example 1 Input: 1 β 20 β 3 β 5 β 50 β 2 β 100 β 15 β 9
Process: Group 1 (size=1): [1] β stays as [1]
Group 2 (size=2): [20,3] β reversed to [3, 20]
Group 3 (size=3): [5,50,2] β reversed to [2, 50, 5]
Group 4 (size=4): [100,15,9] β only 3 nodes < 4 β leave as is
Output: 1->3->20->2->50->5->100->15->9