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.
It started with three interesting problems on Monday: Add Two Numbers, Subarray Sum Equals K, and Two Sum II - Input Array Is Sorted.
In the problem Add Two Numbers, the two numbers were added to the problem, represented by a linked list, such that every node contains a single digit and the digits are stored in reverse order. The objective is to return the sum as a new linked list. To solve this, I used a loop to iterate over both linked lists, adding the digits and any carry from the previous addition. This involved edge cases such as when one list was longer than the other or when there was a carry left over after processing all the nodes. Working through this problem improved my ability to think critically about linked list manipulation and carry-over logic.
Next, I solved Subarray Sum Equals K. This one was more algorithmic; given an array, I had to find the total number of subarrays whose sum equals some given value k. Initially, using brute force helped me understand how it works, but optimization came in when I implemented a hash map to store cumulative sums. This would allow me to check whether a given sum for some subarray had occurred before, significantly increasing efficiency.
Finally, I solved Two Sum II - Input Array Is Sorted. This variant was slightly easier to solve than the original problem as it utilized the fact that the input array was sorted. Using a two-pointer technique, I found the two numbers that summed to the target value. The pointers started at the two ends of the array and moved inwards based on whether the sum of the two was either too low or too high. This was a fantastic exercise for using sorted data to get optimized solutions.
The end of Monday was satisfying as I completed these problems, a mix of linked list operations and algorithmic thinking which set up a good ground for the rest of the week.
Top comments (0)