Category Archives: Dynamic Programming

Sum of all substrings of a string representing a number | Set 1March 26, 2017

Given a integer represented as a string, we need to get the sum of all possible substrings of this string. Examples: Input : num =… Read More »

Modify array to maximize sum of adjacent differencesMarch 23, 2017

Given an array, we need to modify values of this array in such a way that sum of absolute differences between two consecutive elements is… Read More »

Count of strings that can be formed using a, b and c under given constraintsMarch 19, 2017

Given a length n, count the number of strings of length n that can be made using ‘a’, ‘b’ and ‘c’ with at-most one ‘b’… Read More »

Highway Billboard ProblemMarch 13, 2017

Consider a highway of M miles. The task is to place billboards on the highway such that revenue is maximized. The possible sites for billboards… Read More »

Gold Mine ProblemMarch 4, 2017

Given a gold mine of n*m dimensions. Each field in this mine contains a positive integer which is the amount of gold in tons. Initially… Read More »

Finding the maximum square sub-matrix with all equal elementsMarch 2, 2017

Given a N x N matrix, determine the maximum K such that K x K is a submatrix with all equal elements i.e., all the… Read More »

Number of subsequences in a string divisible by nFebruary 27, 2017

Given a string consisting of digits 0-9, count the number of subsequences in it divisible by m. Examples: Input : str = “1234”, n =… Read More »

Maximum path sum that starting with any cell of 0-th row and ending with any cell of (N-1)-th rowFebruary 25, 2017

Given a N X N matrix Mat[N][N] of positive integers. There are only three possible moves from a cell (i, j) (i+1, j) (i+1, j-1)… Read More »

Size of array after repeated deletion of LISFebruary 23, 2017

Given an array arr[0..n-1] of positive element. The task is to print remaining elements of arr[] after repeated deletion of LIS (of size greater than… Read More »

Probability of getting at least K heads in N tosses of CoinsFebruary 21, 2017

Given N number of coins, the task is to find probability of getting at least K number of heads after tossing all the N coins… Read More »

Count binary strings with k times appearing adjacent two set bitsFebruary 20, 2017

Given two integers n and k, count the number of binary strings of length n with k as number of times adjacent 1’s appear. Examples:… Read More »

Check if all people can vote on two machinesFebruary 19, 2017

There are n people and two identical voting machines. We are also given an array a[] of size n such that a[i] stores time required… Read More »

Friends Pairing ProblemFebruary 18, 2017

Given n friends, each one can remain single or can be paired up with some other friend. Each friend can be paired only once. Find… Read More »

Minimum Sum Path In 3-D ArrayFebruary 17, 2017

Given a 3-D array arr[l][m][n], the task is to find the minimum path sum from the first cell of array to the last cell of… Read More »

Printing brackets in Matrix Chain Multiplication ProblemFebruary 12, 2017

Prerequisite : Dynamic Programming | Set 8 (Matrix Chain Multiplication) Given a sequence of matrices, find the most efficient way to multiply these matrices together.… Read More »