Recursion

- Greedy, knapsack, Recursion

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…

Read More

- Dynamic Programming, edit-distance, Mathematical, Recursion, Strings

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

Read More

- Binary Search Tree, Binary Search Trees, DFS, Mathematical, Recursion, Tree

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

Read More