Hello everyone!
This is the official first post (not counting previous intro post) of this blog. So let me walk you through what I have coded today.
Morning I woke up late (weekend mood :P) and didn’t do much till the evening. Evening I set up this blog and wrote my first post. Only then I started my coding today.
First, I solved the daily leetcode challenge. It was Minimum Number of Arrows to Burst Balloons
I was able to solve it on my own. My approach was to sort the balloons based on the starting position and then we keep a current pointer to keep track of the starting point of the current arrow window and another variable to keep track of minimum end value while traversing. we update cur and increment arrow count whenever we findย a balloon with starting point greater than the current minimum end value. we check and update min end value every iteration. This is almost similar to the given approach. But that has only one first_end_min value updated every time. But anyways I am happy that I was able to solve it. The time complexity is O(n*log n) because we are sorting and Space complexity is O(1)
Next comes the Candy Crush which brings us to the title of the blog today. I named this because I spent nearly around 2 solving the problem, that too I looked up the solution. It was a little implementation heavy. Anyway here’s the problem Candy Crush.
The approach is to basically check 3 length windows both column wise and length wise and make them negative (this is essentially crushing the candies) and set a boolean found to true meaning we have some crushes. Next we have to rearrange the values (i.e gravity) where we start from the end of every column with 2 pointers (read and write). We move the read until we get a positive value (we skip empty rows) and once we find it, we move update write with read position value andย increment write (read we take in a for loop). After read reaches the top of the array that means we have updated all the new positions. But we have to delete all the old ones which are from current write position to the top. Next we do this until we have found is true and return the given board itself modified inplace. Here the space complexity is O((row*col)^2). This a little tricky to get. We know row*col because we have to traverse the entire board to crush the candies. Once we find a match we’ll traverse that whole row or column to find all the candy links. So that would be O(row/3 *col) + O(col/3*row) multiplied by O(row*col) gives O((row*col)^2). Space Complexity is O(1)
Later I participated in my first weekly leetcode contest. LeetCode Contest 210ย I was able to solve 1,2 questions. I was just a minute late for my submission of 3 ๐ and I didnt even get the chance for 4th one. But yeah for my 1st contest not so bad I guess. Let’s do better in the next week.
Yeah that about sums up what I coded today. Actually I was planning on completing my doodle jump tutorial but I didn’t get the time. So that one’s for tomorrow. And one last thing, I was actually planning on doing the #100DaysOfCode on linkedin but. I chickened out. So instead I started this blog. So this is officially day #1 of #100DaysOfCode and also of #30DaysOfCode (just in case :P).
See you tomorrow!
Leave a Reply