Leetcode

1463. Cherry Pickup II

We are given a grid where each cell represents the number of cherries available. Two robots start at the top-left corner of the grid and must traverse down to the bottom-right corner. Each robot can move only in three directions: down, right, or diagonally down-right. However, the robots cannot occupy the same cell at the…

Leetcode

279. Perfect Squares

The Perfect Squares problem is a classic dynamic programming challenge where the goal is to find the minimum number of perfect square numbers (numbers that can be expressed as the square of an integer) that sum up to a given positive integer ‘n’. In this blog, we’ll explore the problem, understand its intuition, and implement…

Leetcode

62. Unique Paths

Problem Statement There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m – 1][n – 1]). The robot can only move either down or right at any point in time. Given the two integers m and n, return the number of possible unique paths that…

Leetcode

1235. Maximum Profit in Job Scheduling

Efficiency is key when it comes to managing multiple jobs with varying start times, end times, and profits. In such scenarios, making the right choices can lead to a significant increase in overall profit. This is where dynamic programming comes to the rescue. In this blog, we’ll explore a Java solution that optimizes job scheduling…

Leetcode

746. Min Cost Climbing Stairs

You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with index 1. Return the minimum cost to reach the top of the floor. Example 2: Solution: DP https://leetcode.com/problems/min-cost-climbing-stairs/description/?envType=study-plan-v2&id=dynamic-programming

Leetcode

1137. N-th Tribonacci Number

The Tribonacci sequence Tn is defined as follows:  T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. https://leetcode.com/problems/n-th-tribonacci-number/description/?envType=study-plan-v2&id=dynamic-programming

Leetcode

Out of Boundary Paths

Problem Statement: https://leetcode.com/explore/challenge/card/june-leetcoding-challenge-2021/606/week-4-june-22nd-june-28th/3790/ After solving a few similar problems, I see a pattern here. Whenever you want to do an exhaustive search. First write a recursive brute force solution, which will definitely fail because of high time complexity. After that memorize the answer for a state so you don’t have to calculate a particular cell…

Leetcode

Minimum Path Sum

Problem statement Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. If you notice this problem, from a position we can move right or down….