# Category Archives: Dynamic Programming

## Count Distinct SubsequencesSeptember 18, 2016

Given a string, find count of distinct subsequences of it. Examples: Input : str = “gfg” Output : 7 The seven distinct subsequences are “”,… Read More »

## Non-crossing lines to connect points in a circleSeptember 14, 2016

Consider a circle with n points on circumference of it where n is even. Count number of ways we can connect these points such that… Read More »

## Count digit groupings of a number with given constraintsSeptember 8, 2016

We are given a string consisting of digits, we may group these digits into sub-groups (but maintaining their original order). The task is to count… Read More »

## Minimum cost to fill given weight in a bag

You are given a bag of size W kg and you are provided costs of packets different weights of oranges in array cost[] where cost[i]… Read More »

## A Space Optimized DP solution for 0-1 Knapsack ProblemAugust 31, 2016

Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.… Read More »

## Find number of times a string occurs as a subsequence in given stringAugust 29, 2016

Given two strings, find the number of times the second string occurs in the first string, whether continuous or discontinuous. Examples: Input: string a =… Read More »

## Minimum Cost To Make Two Strings IdenticalAugust 26, 2016

Given two strings X and Y, and two values costX and costY. We need to find minimum cost required to make the given two strings… Read More »

## Find all combinations of k-bit numbers with n bits set where 1 <= n <= k in sorted orderAugust 19, 2016

Given a number k, find all the possible combinations of k-bit numbers with n-bits set where 1 <= n <= k. The solution should print… Read More »

## Longest Geometric ProgressionAugust 8, 2016

Given a set of numbers, find the Length of the Longest Geometrix Progression (LLGP) in it. The common ratio of GP must be an integer.

## Weighted Job Scheduling | Set 2 (Using LIS)August 3, 2016

Given N jobs where every job is represented by following three elements of it. 1. Start Time 2. Finish Time 3. Profit or Value Associated… Read More »

## Print Maximum Length Chain of PairsJuly 31, 2016

You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can… Read More »

## Find Jobs involved in Weighted Job SchedulingJuly 27, 2016

Given N jobs where every job is represented by following three elements of it. 1. Start Time 2. Finish Time 3. Profit or Value Associated… Read More »

## Printing Longest Bitonic SubsequenceJuly 25, 2016

The Longest Bitonic Subsequence problem is to find the longest subsequence of a given sequence such that it is first increasing and then decreasing. A… Read More »

## Printing Maximum Sum Increasing SubsequenceJuly 24, 2016

The Maximum Sum Increasing Subsequence problem is to find the maximum sum subsequence of a given sequence such that all elements of the subsequence are… Read More »

## Find minimum adjustment cost of an arrayJuly 21, 2016

Given an array of positive integers, replace each element in the array such that the difference between adjacent elements in the array is less than… Read More »