# Category Archives: Dynamic Programming

## Count number of paths with at-most k turns

Given a “m x n” matrix, count number of paths to reach bottom right from top left with maximum k turns allowed. What is a… Read More »

## Count number of ways to partition a set into k subsets

Given two numbers n and k where n represents number of elements in a set, find number of ways to partition the set into k… Read More »

## Bell Numbers (Number of ways to Partition a Set)

Given a set of n elements, find number of ways of partitioning it. Examples: Input: n = 2 Output: Number of ways = 2 Explanation:… Read More »

## Collect maximum coins before hitting a dead end

Given a character matrix where every cell has one of the following values. ‘C’ –> This cell has coin ‘#’ –> This cell is a… Read More »

## Number of paths with exactly k coins

Given a matrix where every cell has some number of coins. Count number of ways to reach bottom right from top left with exactly k… Read More »

## Find minimum possible size of array with given rules for removing elements

Given an array of numbers and a constant k, minimize size of array with following rules for removing elements. Exactly three elements can be removed… Read More »

## Find number of solutions of a linear equation of n variables

Given a linear equation of n variables, find number of non-negative integer solutions of it. For example,let the given equation be “x + 2y =… Read More »

## Find the longest path in a matrix with given constraints

Given a n*n matrix where all numbers are distinct, find the maximum length path (starting from any cell) such that all cells along the path… Read More »

## Count number of ways to cover a distance

Given a distance ‘dist, count total number of ways to cover the distance with 1, 2 and 3 steps. Examples: Input: n = 3 Output:… Read More »

## Count even length binary sequences with same sum of first and second half bits

Given a number n, find count of all binary sequences of length 2n such that sum of first n bits is same as sum of… Read More »

## Longest Repeating Subsequence

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

## Bitmasking and Dynamic Programming | Set 1 (Count ways to assign unique cap to every person)

Consider the below problems statement. There 100 different types of caps each having a unique id from 1 to 100. Also, there ‘n’ persons each… Read More »

## Maximum weight transformation of a given string

Given a string consisting of only A’s and B’s. We can transform the given string to another string by toggling any character. Thus many transformations… Read More »

## Count total number of N digit numbers such that the difference between sum of even and odd digits is 1

Given a number n, we need to count total number of n digit numbers such that the sum of even digits is 1 more than… Read More »

## Count of n digit numbers whose sum of digits equals to given sum

Given two integers ‘n’ and ‘sum’, find count of all n digit numbers with sum of digits as ‘sum’. Leading 0’s are not counted as… Read More »