Featured Post

Hello! and Greetings! Nice to see you on my blog.

 

8/20/2022

LeetCode Day 30

 I started practicing medium difficulty questions on leetcode starting with three sum. That was a difficult problem. I haven't done two sum 2 which was the sub problem of three sum. So three sum ended up being two sum 2 but slightly trickier.




I ended up using a very inefficient solution that kept duplicates. The solution format I was going for while solving this problem was creating combinations while iterating through the nums array. It worked! But it kept duplicates! I tried making the array into a set, then back to an array. Didn't work 😅. I also tried sorting the initial array and then skipping the duplicate numbers. Didn't work😅. 


I ended up watching neetcode....



Learned thangs:
- starters, sorting a list can be done two ways. nums.sort()
or sorted(nums). (totally forgot about this, been a while since I've visited arrays section)
- Second, sets can't really be used on double lists. List inside a list. It's because a list itself is not hashable, so the set doesn't know what to do. No real way to delete duplicated lists without getting you're hands dirty.
- Third, some mediums are so dang hard. But its a learning process. My thought process went pretty well this time. I started with the brute force, and worked my way to my solution. I just didn't think about how 3 sum could easily become a two sum problem. I should have drawn on my past experiences more.
- This problem needed a left and right pointer to complete it which is crazy. Didn't even need a hashmap. I should have done two sum 2 first.... Doing it step by step is always better.
- Everyone has a hard time with leetcode. Take youre time and work through it. You'll eventually get better.





No comments:

Post a Comment