Hey, I am so delighted to say that I was able to take the next step in my competitive programming journey. I started from knowing nothing about linked lists and have now begun learning some of the tougher concepts. After covering the basics, I moved on to more complicated topics. I’ve learned about linked lists and tackled a few related questions over the past few days. Today, I focused on Dojo-related questions, as I need them for my upcoming dojo this week. I made a plan with that in mind.
On Wednesday, problems were solved which are based on removing duplicates and removing consecutive zero sum nodes in linked lists. The problems involved are Remove Duplicates from Sorted List, Remove Duplicates from Sorted List II, and Remove Zero Sum Consecutive Nodes from Linked List.
The first problem, Remove Duplicates from Sorted List, required the removal of duplicate nodes from a sorted linked list such that every element occurred only once. I used a simple traversal approach comparing each node with its next and skipping over duplicates. This was a pretty straightforward problem, but it really emphasized understanding list traversal and pointer updates.
It did require extra attention with Remove Duplicates from Sorted List II. Now, here instead of keeping just one instance of each value I needed to completely eliminate duplicates. This called for careful management of nodes that happen to come up consecutively. Here, I've used a dummy node so that there is no mess with handling of edge cases when updating the head of the list.
The last problem of the day was the most challenging, Remove Zero Sum Consecutive Nodes from Linked List. I had to find and remove consecutive nodes whose sum is zero. To solve this, I used a prefix sum approach, maintaining a map of previously seen sums. This allowed me to efficiently track subarrays of nodes summing to zero and adjust pointers to remove them.
Top comments (0)