Skip to content

Category Archives: Dynamic Programming

There are some glasses with equal capacity as 1 litre. The glasses are kept as follows:  1 2 3 4 5 6 7 8 9… Read More
Given a graph and a source vertex src in graph, find shortest paths from src to all vertices in the given graph. The graph may… Read More
Write a function that takes two parameters n and k and returns the value of Binomial Coefficient C(n, k). Example:   Input: n = 4 and k… Read More
Given a string, find the longest substring which is palindrome.  For example,  Input: Given string :"forgeeksskeegfor", Output: "geeksskeeg" Input: Given string :"Geeks", Output: "ee" Recommended:… Read More
You are given a set of n types of rectangular 3-D boxes, where the i^th box has height h(i), width w(i) and depth d(i) (all… Read More
We have discussed Dynamic Programming solution for Longest Increasing Subsequence problem in this post and a O(nLogn) solution in this post. Following are commonly asked… Read More
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
Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Put line breaks… Read More
  Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.  Example: … Read More
Partition problem is to determine whether a given set can be partitioned into two subsets such that the sum of elements in both subsets is… Read More
Given a string, a partitioning of the string is a palindrome partitioning if every substring of the partition is a palindrome. For example, “aba|b|bbabb|a|b|aba” is… Read More
  The Floyd Warshall Algorithm is for solving the All Pairs Shortest Path problem. The problem is to find shortest distances between every pair of… Read More
Given an array arr[0 … n-1] containing n positive integers, a subsequence of arr[] is called Bitonic if it is first increasing, then decreasing. Write… Read More
Given an array of random numbers. Find longest increasing subsequence (LIS) in the array. I know many of you might have read recursive and dynamic programming… Read More
Given an array of n positive integers. Write a program to find the sum of maximum sum subsequence of the given array such that the… Read More