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

Pascal’s Triangle

Problem Statement The logic is in the above gif itself. We have to do the following things.1. Hardcode 1 at 0th and last position of every row.2. If we are at the ith row and jth column. We can get the value of pascal[i][j]. pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];

BFS daigram
Leetcode

Open the Lock

Problem Statement To be frank, as I read the problem I realized it is a BFS problem. Let’s see what was my thought, we have to count the number of steps to reach the final string, this denotes we have to traverse the intermediate nodes. We cannot directly jump to the final string and apply…

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….

Leetcode

N Queen Problem

Problem Statement: LeetCode May 2021 – Day 22 8 Queen problem is a standard example in the backtracking world. Whenever you start learning the backtracking paradigm this is the first problem you may encounter. So the question is how to solve this problem. For any given problem it is very rare that we directly come…