Category Archives: Dynamic Programming

Given a string S of length N and a positive integer K, the task is to find the minimum total cost of picking K unique… Read More
Given an array arr[] having N pair of integers of the form (x, y), the task is to maximize the sum y values in selected… Read More
Given three integers M, N and K, the task is to count all the possible paths from the cell (0, 0, 0) to cell (M-1,… Read More
Given a binary string S of size N, and a 2D array Q[][] of queries consisting of M pairs of the form {L, R}, the… Read More
Given two integers N and M (1 ≤ N, M ≤ 100) denoting the total number of 1s and 0s respectively. The task is to… Read More
Given an integer N and three N x N matrices X[][], Y[][], and Z[][], the task is to calculate the minimum cost required to reach… Read More
Given two points P1(x1, y1) and P2(x2, y2) of a matrix, the task is to find the minimum cost to reach P2 from P1 when:… Read More
Given an array arr[] containing integers. The task is to find the number of decreasing subarrays with a difference of 1.  Examples:  Input: arr[] =… Read More
An array is given, find length of the subarray having maximum sum. Examples :  Input : a[] = {1, -2, 1, 1, -2, 1} Output… Read More
An array is given, find length of the subarray having maximum sum. Examples :  Input : a[] = {1, -2, 1, 1, -2, 1} Output… Read More
An array is given, find length of the subarray having maximum sum. Examples :  Input : a[] = {1, -2, 1, 1, -2, 1} Output… Read More
An array is given, find length of the subarray having maximum sum. Examples :  Input : a[] = {1, -2, 1, 1, -2, 1} Output… Read More
An array is given, find length of the subarray having maximum sum. Examples :  Input : a[] = {1, -2, 1, 1, -2, 1} Output… Read More
Given two integers N and K, the task is to find the total number of ways of representing N as the sum of positive integers… Read More
For every node in an undirected tree, find the sum of length of paths from it to all other nodes, using Tree Rerooting technique. Rerooting… Read More