# Category Archives: Dynamic Programming

## Choose maximum weight with given weight and value ratioJune 19, 2017

Given weights and values of n items and a value k. We need to choose a subset of these items in such a way that… Read More »

## Count Balanced Binary Trees of Height hJune 17, 2017

Given a height h, count and return the maximum number of balanced binary trees possible with height h. A balanced binary tree is one in… Read More »

## Minimum time to write characters using insert, delete and copy operationJune 14, 2017

We need to write N same characters on a screen and each time we can insert a character, delete the last character and copy and… Read More »

## Counts paths from a point to reach OriginJune 13, 2017

You are standing on a point (n, m) and you want to go to origin (0, 0) by taking steps either left or down i.e.… Read More »

## Pyramid form (increasing then decreasing) consecutive array using reduce operationsJune 12, 2017

We have N (where N > 2) stones of various heights laid out in a row. Task is to make a pyramid from given array… Read More »

## Count the number of ways to tile the floor of size n x m using 1 x m size tilesJune 10, 2017

Given a floor of size n x m and tiles of size 1 x m. The problem is to count the number of ways to… Read More »

## Maximum sum in a 2 x n grid such that no two elements are adjacentJune 8, 2017

Given a rectangular grid of dimension 2 x n. We need to find out the maximum sum such that no two chosen numbers are adjacent,… Read More »

## Ways to sum to N using array elements with repetition allowedJune 6, 2017

Given a set of m distinct positive integers and a value ‘N’. The problem is to count the total number of ways we can form… Read More »

## Sequences of given length where every element is more than or equal to twice of previousJune 4, 2017

Given two integers m & n, find the number of possible sequences of length n such that each of the next element is greater than… Read More »

## Number of substrings divisible by 8 but not by 3June 2, 2017

Given a string of digits “0-9”. The task is find the number of substrings which are divisible by 8 but not by 3. Examples: Input… Read More »

## Dynamic Programming | Building Bridges

Consider a 2-D map with a horizontal river passing through its center. There are n cities on the southern bank with x-coordinates a(1) … a(n)… Read More »

## Minimum insertions to sort an arrayMay 31, 2017

Given an array of integer numbers, we need to sort this array in a minimum number of steps where in one step we can insert… Read More »

## Shortest Uncommon SubsequenceMay 26, 2017

Given two strings S and T, find length of the shortest subsequence in S which is not a subsequence in T. If no such subsequence… Read More »

## Minimum number of deletions and insertions to transform one string into anotherMay 21, 2017

Given two strings ‘str1’ and ‘str2’ of size m and n respectively. The task is to remove/delete and insert minimum number of characters from/in str1… Read More »

## Count number of ways to jump to reach endMay 20, 2017

Given an array of numbers where each element represents the max number of jumps that can be made forward from that element. For each array… Read More »