Day 11 to Day 20 - galacemiguel/100DaysOfCode GitHub Wiki
Day 11
Populating Next Right Pointers in Each Node (In Progress)
Today, the training wheels came off. And I definitely stumbled. I don't yet have a way to address problems I'm not able to solve within a reasonable (1.5 hours+) amount of time. It might be foolish to keep pressing as these are the type of things to frustrate you and then bring you further away from the solution.
So for today, I failed to a find an answer, but will continue again tomorrow. Perhaps if within 2 days I am not able to find a solution to the same problem, I will reach for external help. But for now: to be continued.
Day 12
Populating Next Right Pointers in Each Node
Funny how some time away and a loosening of thinking can bring so much clarity. I definitely overthought this one as the answer was much simpler than my initial attempted solutions.
I drew a binary tree for myself and just managed to see one part of the problem I had already "figured out" differently and the answer soon followed. Not much more I can write about it than that. Didn't even require any data structure of any kind.
Day 13
Populating Next Right Pointers in Each Node II (In Progress)
Stuck again, but that's okay.
I'm more than halfway there (37/61 test cases passed). But it might not be wise to keep pushing since it's late and I'm not in the right mind. Made use of a dictionary for the first time solving these types of problems and it got me further along. Might be another trick I'm missing.
Day 14
Populating Next Right Pointers in Each Node II
Back in the game! Was forced to take a long break to (finally) put some nagging projects I had to rest. But I keep coming back to this because I fully intend to see it through! 💪
I didn't end up pursuing the dictionary route. Turns out it could still just be solved with good ol' fashioned recursion and not some obscure trick as I had initially suspected. It was also just the flow of my initial logic that was off. Managed to see my error by manually running my code in my head for the test case I was failing.
Day 15
Lowest Common Ancestor of a Binary Tree
I knew almost straightaway what my approach to solving this problem was going to be.
I struggled a bit with the actual code-writing portion because of some of Python's (and maybe LeetCode's) eccentricities – like with how the former passes lists by reference and not by value. My solution though – when I eventually got to it – was quite slow and memory inefficient. Looking forward to reading the solution article and analyzing some of the faster submissions.
EDIT: Turns out my solution runs in O(N) time just like the others. Might be some inefficient method or comparison I'm doing. Although, the fastest solution presented is still objectively better than mine because it eliminates the need for backtracking. Good stuff.
Day 16
Serialize and Deserialize Binary Tree (In Progress)
Managed to write the serialization part of the problem without much hiccup yet (afaik). 🤔 Stopping in the middle of the deserialize portion for now and will continue tomorrow. This part is a bit more involved than the former I think.
Day 17
Serialize and Deserialize Binary Tree
Problem was not really that difficult. All it mostly took was a queue on hand (and very many tries to overcome the edge cases 😅). Apart from that, not really much to write about. That was the last problem in the Binary Tree module though, so for the next few days, I will be working on a different set of problems.
On to the next ones!
Day 18
Took on the classic binary search problem. I've studied and answered this one before so it wasn't much trouble. Love to see this kind of problem though because I think it's one of the foundation algorithms in Computer Science.
The next few of the succeeding problems I will be answering will center around Binary Search because the module I just started is about the Binary Search algorithm and the many forms it can take. Excited! 🤩
Day 19
Sqrt(x) (In Progress)
The algorithm to get this working is quite clear my mind. I just have yet to be able to translate it properly into code. A bit unwell right now so that is definitely shortening my patience. I know that if I stop blindly modifying my code, sit down, and really think about each step of what needs to happen in this algorithm, then I will get this to work.
Day 20
Finally managed to get down in code what was in my head since last night. Turns out helper functions can really help with that because they help break down your thoughts into isolated modular steps.
Turns out my solution too closely followed the binary search template though since I was still needlessly producing an array. Faster solutions made use of plain old math. Don't yet understand those, but going to read up on the problem article to help shed some light on that approach.
EDIT: Apparently I neglected a key constraint in the problem, which was that the answer only need be an integer. My solution calculated for too much only to throw it away in the end. Need to be mindful of that. Also, numbers are already inherently sorted, so the arrays really were unnecessary. Another thing to look out for in the next few problems.