Skip to main content

Posts

Showing posts with the label Dynamic Programming

Arrays

DP :Rat maze, Minimum cost path

Robot walked from the upper left to the lower right, can only go down and to the right, the number of each grid is height, If the next cell height is higher than the current, we must pay the difference cost, otherwise no cost, Find the minimum cost to reach the lower right corner, Follow up 1, print the minimum cost path;  November 25, 2017 in United States | Facebook SDE1 Problem 2 --> Given a non-empty string s, you may delete at most k characters. Judge whether you can make it a palindrome. Remove a character from a string to make it a palindrome Given a string, we need to check whether it is possible to make this string a palindrome after removing exactly one character from this. Examples: Input : str = “abcba” Output : Yes we can remove character ‘c’ to make string palindrome Input : str = “abcbea” Output : Yes we can remove character ‘e’ to make string palindrome Input : str = “abecbea” It is not possible to make...

DP: Problem Types

Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again. Dynamic programming is discussed in next post i.e. 1) Overlapping Subproblems Memotization  Tabulation 2) Optimal Substructure What is subsequences  ? A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous.  The list of all subsequences for the word " apple " would be " e, l, le, p, pe, pl, ple, p, pe, pl, ple, pp, ppe, ppl, pple, a, ae, al, ale, ap, ape, apl, aple, ap, ape, apl, aple, app, appe, appl, apple ". Longest Increasing Subsequence Input : arr[] = {3 , 10 , 2, 1, 20 } Output : Length of LIS = 3 The longest increasing subsequence is 3, 10, 20 Input : arr[] = {3, 2} Output : Length of LIS = 1 The longest increasing subsequences are {3} and {2} Input :...