Category Archives: Dynamic Programming

Friends Pairing Problem

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 out the total number of ways in which friends can remain single or can be paired up. Examples: Input : n = 3 Output : 4 Explanation {1}, {2}, {3}… Read More »

Minimum Sum Path In 3-D Array

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 array. We can only traverse to adjacent element, i.e., from a given cell (i, j, k), cells (i+1, j, k), (i, j+1, k) and (i, j, k+1) can be traversed,… Read More »

Printing brackets in Matrix Chain Multiplication Problem

Prerequisite : Dynamic Programming | Set 8 (Matrix Chain Multiplication) Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is not actually to perform the multiplications, but merely to decide in which order to perform the multiplications. We have many options to multiply a chain of matrices… Read More »

Probability of Knight to remain in the chessboard

Given an NxN chessboard and a Knight at position (x,y). The Knight has to take exactly K steps, where at each step it chooses any of the 8 directions uniformly at random. What is the probability that the Knight remains in the chessboard after taking K steps, with the condition that it can’t enter the… Read More »

LCS (Longest Common Subsequence) of three strings

Given 3 strings of all having length < 100,the task is to find the longest common sub-sequence in all three given sequences. Examples: Input : str1 = “geeks” str2 = “geeksfor” str3 = “geeksforgeeks” Output : 5 Longest common subsequence is “geeks” i.e., length = 5 Input : str1 = “abcd1e2” str2 = “bc12ea” str3… Read More »