# Dynamic Programming

### Count of index subsets such that maximum of values over these indices in A is at least total sum over B

#include using namespace std;  int countValidSubsets(int A[], int B[], int N){    int ans = 0;      vector AB(N);              int mx = INT_MIN;                  for (int i =…

### Count of valid arrays of size P with elements in range [1, N] having duplicates at least M distance apart

#include using namespace std;  int calculate(int position, int used, int unused, int P,              int M, vector& dp){        if (position == P) {                        return unused…

### Minimize the count of characters to be added or removed to make String repetition of same substring

function getMin(x, y, z) {            return Math.min(Math.min(x, y), z);        }                                function editDistance(str1, str2, m, n)        {                                 let dp = new Array(m + 1).fill(new Array(n +…

### Maximum sum of K elements selected from a Matrix

#include using namespace std;int maximumSum(vector& prefixSum,               vector& dp,               int K, int N, int rem, int id){        int ans = INT_MIN;        if (rem == 0)        return…

### Longest subarray with all even or all odd elements

Given an array A[ ] of N non-negative integers, the task is to find the length of the longest sub-array…

### Count N-digit numbers such that every position is divisible by the digit at that position

Given a positive integer N, the task is to count the number of N-digit numbers such that every index (1-based…

### Maximum profit after buying and selling the stocks with transaction fees | Set 2

Given an array arr[] of positive integers representing prices of stocks and an integer transactionFee, the task is to find…

### Maximum number of groups that can receive fresh donuts distributed in batches of size K

import java.io.*;import java.util.*;class GFG {            static HashMap memo;                public static int dfs(int[] V,                          int left, int K)    {                        int q = 0;                                String key = Arrays.toString(V);        key…