# Category Archives: Dynamic Programming

## Program for Bridge and Torch problemNovember 21, 2017

Given an array of positive distinct integer denoting the crossing time of ‘n’ people. These ‘n’ people are standing at one side of bridge. Bridge… Read More »

## The painter’s partition problemNovember 19, 2017

We have to paint n boards of length {A1, A2…An}. There are k painters available and each takes 1 unit time to paint 1 unit… Read More »

## Given a large number, check if a subsequence of digits is divisible by 8November 13, 2017

Given a number of at most 100 digits. We have to check if it is possible, after removing certain digits, to obtain a number of… Read More »

## Minimum sum submatrix in a given 2D arrayNovember 1, 2017

Given a 2D array, find the minimum sum submatrix in it. Examples: Input : M[][] = {{1, 2, -1, -4, -20}, {-8, -3, 4, 2,… Read More »

## Maximum sum subsequence with at-least k distant elementsOctober 31, 2017

Given an array and a number k, find a subsequence such that Sum of elements in subsequence is maximum Indices of elements of subsequence differ… Read More »

## Number of NGEs to the rightOctober 29, 2017

Given an array of n integers and q queries, print the number of next greater elements to the right of the given index element. Examples:… Read More »

## Length of Longest Balanced SubsequenceOctober 19, 2017

Given a string S, find the length of longest balanced subsequence in it. A balanced string is defined as:- A Null string is a balanced… Read More »

## Tile Stacking Problem

A stable tower of height n is a tower consisting of exactly n tiles of unit height stacked vertically in such a way, that no… Read More »

## Counting pairs when a person can form pair with at most oneOctober 18, 2017

Consider a coding competition on geeksforgeeks practice. Now their are n distinct participants taking part in the competition. A single participant can make pair with… Read More »

## Count of strings where adjacent characters are of difference oneOctober 16, 2017

iven a number n, count number of strings of length n such that every string has adjacent characters with difference between ASCII values as 1.… Read More »

## Longest Repeated SubsequenceOctober 10, 2017

Given a string, print the longest repeating subseequence such that the two subsequence don’t have same string character at same position, i.e., any i’th character… Read More »

## Sub-tree with minimum color difference in a 2-coloured treeOctober 9, 2017

A tree with N nodes and N-1 edges is given with 2 different colours for its nodes. Find the sub-tree with minimum colour difference i.e.… Read More »

## Longest alternating sub-array starting from every index in a Binary ArrayOctober 8, 2017

Given an array containing only 0s and 1s. For each index ‘i‘(0 index), find length of the longest alternating sub-array starting from ‘i‘ to ‘j‘… Read More »

## Longest Common Subsequence with at most k changes allowedOctober 5, 2017

Given two sequence P and Q of numbers. The task is to find Longest Common Subsequence of two sequence if we are allowed to change… Read More »

## Count all subsequences having product less than K

Given a non negative array, find the number of subsequences having product smaller than K. Examples: Input : [1, 2, 3, 4] k = 10… Read More »