1 week before, one of my seniors told me to work on hash table problems more since they are always relevant in interviews and practical day-to-day coding. So, I did. I just avoided looking at hard problems like my life depended on it. After doing a 20-ish mix of easy and medium problems, I found the minimum subarray problem.
So, I attempted my first Hard difficulty problem on leetcode, and I am afraid to say that it felt like they dumbed it down for a hard difficulty. I'm not sure how I feel about it. One look at the problem told me what steps I needed to take. After doing 10 easy and medium problems on subarrays, the familiarity of the pattern felt good.
It's not to say that I didn't need help from the hints; I did, but when I discussed it with a senior, he approved of my thinking process but gave a bit more hints on some edge cases.
I was almost there but merging the sliding window algorithm and hashmap DS was a bit tricky (for a newbie!). I gobbled up a messy solution, and it worked. Below is the solution after I tweaked it a bit.
To calm my nerves, I then attempted to reverse a linked list. Then, I went back and re-implemented the solution using Python (my less-used language) to see if I wasn't just regurgitating the syntax from the pattern.
Top comments (0)