Category Archives: Dynamic Programming

Coin game winner where every player has three choicesAugust 26, 2017

A and B are playing a game. At the beginning there are n coins. Given two more numbers x and y. In each move a… Read More »

Shortest possible combination of two stringsAugust 24, 2017

Compute the shortest string for a combination of two given strings such that the new string consist of both the strings as its subsequences. Examples… Read More »

Maximum games played by winnerAugust 20, 2017

There are N players which are playing a tournament. We need to find the maximum number of games the winner can play. In this tournament,… Read More »

Subset Sum Problem in O(sum) spaceAugust 17, 2017

Given an array of non-negative integers and a value sum, determine if there is a subset of the given set with sum equal to given… Read More »

Convert to Strictly increasing array with minimum changesAugust 15, 2017

Given an array of n integers. Write a program to find minimum number of changes in array so that array is strictly increasing. In strictly… Read More »

Smallest sum contiguous subarrayJuly 30, 2017

Given an array containing n integers. The problem is to find the sum of the elements of the contiguous subarray having the smallest(minimum) sum. Examples:… Read More »

Ways of transforming one string to other by removing 0 or more charactersJuly 27, 2017

Given two sequences A, B, find out number of unique ways in sequence A, to form a subsequence of A that is identical to the… Read More »

Find length of longest subsequence of one string which is substring of another stringJuly 9, 2017

Given two string X and Y. The task is to find the length of longest subsequence of string X which is substring in sequence Y.… Read More »

Non-decreasing subsequence of size k with minimum sumJuly 5, 2017

Given a sequence of n integers, you have to find out the non-decreasing subsequence of length k with minimum sum. If no sequence exists output… Read More »

Paper Cut into Minimum Number of Squares | Set 2

Given a paper of size A x B. Task is to cut the paper into squares of any size. Find the minimum number of squares… Read More »

Count of Palindromic substrings in an Index rangeJuly 4, 2017

Given a string str of small alphabetic characters other than this we will be given many substrings of this string in form of index tuples.… Read More »

Find maximum possible stolen value from housesJune 27, 2017

There are n houses build in a line, each of which contains some value in it. A thief is going to steal the maximal value… Read More »

Number of n-digits non-decreasing integers

Given an integer n > 0, which denotes the number of digits, the task to find total number of n-digit positive integers which are non-decreasing… Read More »

Painting Fence AlgorithmJune 24, 2017

Given a fence with n posts and k colors, find out the number of ways of painting the fence such that at most 2 adjacent… Read More »

Bitmasking and Dynamic Programming | Set-2 (TSP)June 23, 2017

In this post, we will be using our knowledge of dynamic programming and Bitmasking technique to solve one of the famous NP-hard problem “Travelling Salesman… Read More »