Dynamic Programming (DP) is a powerful technique used to solve problems that involve making a sequence of decisions, often with overlapping subproblems. It’s widely regarded as a challenging concept, but with the right approach, it becomes a highly e...
Dynamic programming (DP) is a method for solving complex problems by breaking them down into simpler overlapping subproblems. It’s a favorite topic in Google interviews because it tests a candidate’s ability to recognize patterns and optimize naive s...
Problem https://leetcode.com/problems/shortest-common-supersequence/description/ Leetcode - Shortest Common Supersequence Type - Dynamic programming, String, LCS(Longest Common Subsequence) Difficulty - Hard Approach & Solution The worst case is stri...
Problem https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/description/ Leetcode - Length of Longest Fibonacci Subsequence Type - Dynamic programming Difficulty - Medium Approach & Solution Let DP[prev][curr] is the length of Fibon...
Problem https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/description/ Leetcode - Number of Sub-arrays With Odd Sum Type - Prefix Sum, Dynamic Programming Difficulty - Medium Approach && Solution Since the length of arr can be up to 10^...
Understanding the Problem There is a pyramid given with the length of n. From the bottom to top, the length of the floor is narrowed by 1. # input triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] # output 11 # visualised triangle 2 3 4 6 5 7 4 1 8 3 ...
Recursive Solution class Solution { public int uniquePaths(int m, int n) { return countPath(m-1,n-1); } private int countPath(int i,int j){ if(i == 0 && j == 0)return 1; if(i < 0 || j < 0)return 0; int up ...
Artificial Intelligence (AI) Roadmap 1. Mathematics for AI Linear Algebra (Vectors, Matrices, Eigenvalues) Calculus (Derivatives, Partial Derivatives, Chain Rule) Probability & Statistics (Bayes’ Theorem, Distributions) Optimization (Gradient Des...
Introduction In the realm of algorithm design, tree algorithms are among the most fundamental and widely used techniques. Trees, being hierarchical data structures, appear in a variety of real-world problems, from computer networks and database index...
Introduction In the world of algorithmic problem-solving, Kadane's Algorithm stands out as a powerful technique for solving the maximum subarray sum problem efficiently. The problem asks us to find the contiguous subarray within a one-dimensional arr...