Innovacer | R-1

innovacer logo
innovacer
January 15, 20265 reads

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)

Q1
Reverse Linked List in Increasing Size Groups
Data Structures & AlgorithmsHard

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

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!