Leetcode Solutions

  • LeetCode 763. Partition Labels Solved (Greedy Method)

    The prompt for this problem was honestly kind of confusing. But, what I was able to understand was that we want to maximize the number of partitions we can make, but a letter can only appear in one partition. So for example, if we partition the string into two halves, both halves cannot have the […]

    Read More

  • LeetCode 1899. Merge Triplets to Form Target Triplet Solved (Greedy Method)

    A lot of times with Greedy problems the answer can be very tricky, however with this problem, the answer is pretty intuitive and it’s easy to see that the brute force approach which would potentially be a backtracking approach would be a lot of work, and the time complexity would also be exponential. Using the […]

    Read More

  • 63. Unique Paths II Solved (Dynamic Programming)

    This problem is relatively easy after solving the Unique Paths I problem, it just builds on the same problem by now adding obstacles to the grid. So I had to change the approach a bit. For the recursive approach, it was a matter of just adding more constraints. So, if the index was an index […]

    Read More

  • LeetCode 309. Best Time to Buy and Sell Stock with Cooldown (Dynamic Programming)

    The first step in understanding this problem is understanding the decisions we can make based on the option we have, which will allow us to form a decision tree. So, starting from index 0 we have the option to buy the stock at index/day 0 or just wait and go to the next day. If […]

    Read More

  • LeetCode 62. Unique Path Solved (Dynamic Programming)

    This is a 2-d dynamic programming problem, but it follows the same method of solving we start with a recursive approach, memoize, and finally recognize the pattern to come up with a bottom-up iterative approach. If you looked at just the recursive approach it would be hard to tell this is a 2-d problem, it’s […]

    Read More