# Recursion

### Print all ways to reach the Nth stair with the jump of 1 or 2 units at a time

Given a positive integer N representing N stairs and a person it at the first stair, the task is to…

### Minimize sum of node values by filling given empty Tree such that each node is GCD of its children

#include using namespace std;  class Node {public:    int val;    Node *left, *right;    Node(int val)    {        this->val = val;        left = NULL;        right = NULL;    }};  class Tree {public:    unordered_map depth;              int findDepth(Node*…

### Maximum sum of values of N items in 0-1 Knapsack by reducing weight of at most K items in half

import java.io.*;import java.util.*;  class GFG {          static int maximum(int value[],                       int weight[], int weight1,                       int flag, int K, int index)    {                  if (index >= value.length) {              return…

### 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…

### Sum of all nodes with smaller values at a distance K from a given node in a BST

#include using namespace std;  struct TreeNode {      int data;    TreeNode* left;    TreeNode* right;          TreeNode(int data)    {        this->data = data;        this->left = NULL;        this->right = NULL;    }};  void kDistanceDownSum(TreeNode* root,                      int k, int&…

### Maximum points by traversing from top left of Matrix to bottom right by two persons

#include using namespace std;  const static int MAXR = 20, MAXC = 20;int cache[MAXC][MAXR][MAXC][MAXR],    dp[MAXC][MAXR][MAXC][MAXR];int n, m;vector grid;  int maxMoney(int x1, int y1,…