Featured Post

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

 

9/05/2022

LeetCode Day 31

I'm back from a long break away from leetcode. Long meaning 1 week and a half. So really not that long. But it feels long. I wasn't too rusty, but getting into the rhythm is hard. The first problem went well. I came up with a O(n) time and O(n) space solution. The most optimized was O(1) for space and same time complexity. If an interviewer were to ask me to optimize my problem, I think I could have handled it for sure. The problem was about finding the product sum of every element of the array and populating a result array with that value without the included product of the element at that position. (Product of Array Except Self) With problems that need the values from every other element, its nice to think about prefixes and post fixes. So basically iterating through the array forward once and backward once. Kind of a neat trick. I did well on it.

The second one tho...

Pretty complicated. I was able to solve every part of the problem besides the hardest part which is something that is often in a lot of leetcode problems. This component is the idea of a result array to not have duplicates. This means that the way to solve the leetcode has to be done in a special way where it inherently doesn't allow for duplicates. 

I should draw a little more. Decision trees help solve A LOT of these medium problems. Also, neetcode is the GOAT. He's great. he should work at amazon and google at the same time. he can handle it. 

Here was the drawing I did...




The second one in hindsight is super hard however if its the first time seeing a problem like that. I think an interviewer would appreciate my approach.

One weird thing did happen while I was coding. My list/array skills were failing me. the code was producing a list that was not even close to the thing I wanted. I couldn't find the bug, I hope I run into the issue again to fix it. 

P.S. when passing down a variable in python. REMEMBER THAT ITS PASSED BY REFERENCE. SO BECAREFUL WHEN THE SAME VARIABLE IS USED IN MULTIPLE CALLS. USE .copy() method if you have to.


No comments:

Post a Comment