# Category Archives: Dynamic Programming

## Print negative weight cycle in a Directed Graph

Given a weighted directed graph consisting of V vertices and E edges. The task is to print the cyclic path whose sum of weight is… Read More »

## Count of all subsequences having adjacent elements with different parity

Given an array arr[] of size N, the task is to find the number of non-empty subsequences from the given array such that no two… Read More »

## Count of submatrix with sum X in a given Matrix

Given a matrix of size N x M and an integer X, the task is to find the number of sub-squares in the matrix with… Read More »

## Count of N-digit numbers with absolute difference of adjacent digits not exceeding K

Given two integers N and K, the task is to find the count of N-digit numbers such that the absolute difference of adjacent digits in… Read More »

## Find if there is a path between two vertices in a directed graph | Set 2

Given a Directed Graph and two vertices in it, check whether there is a path from the first given vertex to second. Example: Consider the… Read More »

## Maximize the numbers of splits in an Array having sum divisible by 3

Given an integer array arr of size N. The task is to find the maximum number of splits such that each split has sum divisible… Read More »

## Maximise number of cuts in a rod if it can be cut only in given 3 sizes

Given a rod of length N meters, and the rod can be cut in only 3 sizes A, B and C. The task is to… Read More »

## Maximum cost path in an Undirected Graph such that no edge is visited twice in a row

Given an undirected graph having N vertices and M edges and each vertex is associated with a cost and a source vertex S is given.… Read More »

## Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s

Given two integers N and K, the task is to count the numbers up to N digits such that no two zeros are adjacents and… Read More »

## Minimum cost of reducing Array by merging any adjacent elements repetitively

Given an array arr[] of N numbers. We can merge two adjacent numbers into one and the cost of merging the two numbers is equal… Read More »

## Count of elements having Euler’s Totient value one less than itself

Given an array arr[] of N integers, and a range L to R, the task is to find the total number of elements in the… Read More »

## Count of occurrences of each prefix in a string using modified KMP algorithm

Given a string S of size N, the task is to count the occurrences of all the prefixes of the given string S. Examples: Input:… Read More »

## Maximum size subset with given sum using Backtracking

Given an array arr[] consisting of N integers and an integer K, the task is to find the length of longest subsequence with sum equal… Read More »

## Count of paths in given Binary Tree with odd bitwise AND for Q queries

Given an integer Q representing the number of queries and an array where each query has an integer N. Our task is to iterate through… Read More »

## Finding shortest path between any two nodes using Floyd Warshall Algorithm

Given a graph and two nodes u and v, the task is to print the shortest path between u and v using the Floyd Warshall… Read More »