DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in Competitive Programming

I practiced today with three very important linked list problems: reversing a linked list, finding the middle node, and deleting a node. I feel that it was quite a hard journey yet so rewarding.

The first problem is reversing a linked list. Reverse the nodes in the linked list. That means last becomes a head, and a head will be at the last place. So, I implemented the above two approaches. In the iterative method, I used three pointers to change the links one after the other. This simply reverses the list. The recursive method was neater, but took a little bit of extra time to think about since it involved reversing the rest of the list and then moving the pointers about.

I then progressed to another: find the middle node of a given linked list. The list contained a middle node and therefore, based on this observation, determined its position. In the approach, I used two pointers. The fast pointer basically moved two steps, and the slow pointer only one. By the time the fast pointer reached the end, it pointed to the middle node. It's a very interesting approach, and I like how much more efficient it is as opposed to counting the nodes first and then traversing to the middle.

Finally, I did an exercise of deleting a node from a linked list. The task was about removal of a node either by its value or position. So, I learned how to traverse the list carefully find the node to delete and change the preceding node's pointer to skip the node that is being removed. I handled edge cases, like head deletion or node doesn't exist.

By the end of the day, I was so satisfied at the fact that I had made steady progress in understanding what a linked list is. These problems were excellent for building my confidence at being able to solve even more significant linked list problems in the future.

Top comments (0)