678 questions with no answers
0 votes
0 answers
74 views
Why this code for 0/1 knapsack problem works for some examples?
Problem Statement There are N items, numbered 1, 2, …, N. For each item i (1 ≤ i ≤ N): It has a weight w[i] It has a value v[i] Taro wants to choose some of these N items and carry them home in a ...
0 votes
0 answers
55 views
Valid Parenthesis String, Recursion with memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working but I want to improve it. The challenge I am facing is ...
3 votes
0 answers
58 views
Minimum dominating subgraph
A graph G(V,E) is defined by a set of vertices V and a set of edges E. Given W⊆V, find a connected subgraph G'(V',E') of G that satisfies the following conditions: i) ∀p∈V,∃p'∈V' such that p′ is ...
0 votes
0 answers
59 views
How to determine optimal grouping?
Problem: Given elements and sets that the elements can corespond to, find optimal division these elements to sets, such that number of sets is minimal. Example: 'a' : (1, 2), 'b' : (1, 3), 'c' : (3, 5)...
1 vote
0 answers
47 views
dynamic programming min path grid sum
I recently found a frustrating error in my code. I have two solutions for finding the minimum path sum using dynamic programming (DP). The first solution, which I wrote, doesn't seem to work, even ...
1 vote
0 answers
145 views
How can I find the length of the longest common substring between two strings efficiently?
I have two strings, s1 and s2, and I need to find the length of the longest substring that appears in both strings. The substring must be contiguous in both s1 and s2. For example: If s1 = "...
0 votes
0 answers
76 views
Select top K arrays in an array of arrays, that will consist of the most unique elements
Given an array of arrays, with each sub-array contains unique elements, but among different sub-arrays, there might be the same element. Select the top K sub-arrays, that the union of all elements ...
0 votes
0 answers
245 views
How to dynamically calculate ZigZag Indicator?
I try to implement ZigZag Indicator in TypeScript. My ZigZagCalculation function accepts as a parameters: Bar[] bar, deviation: number And returns array with all the zig-zag points. My bar array has a ...
0 votes
0 answers
19 views
Dynamic Programming Table Extension Causes Incorrect Results for Subset Sum Partition Problem
I'm working on a dynamic programming problem related to counting the number of ways to partition an array into two subsets such that the absolute difference between their sums is equal to a given ...
0 votes
0 answers
258 views
Discount distribution problem (optimization)
Suppose we have a shop and sell 5 different products: A, B, C, D and E. Each product has a fixed base cost of $8.00. Now we represent the amount of each product bought as a tuple (a, b, c, d, e). ...
3 votes
0 answers
66 views
Why does my recursive memoization function cause a 'Maximum Call Stack Exceeded' error in JavaScript?
While solving fabonocci problem using recursion and memoization in JavaScript, I got "Maximum Call Stack Exceeded" error when I try to run it with large inputs. To troubleshoot, I copied the ...
0 votes
0 answers
51 views
Detect Cyclic Islands on a Matrix
On a binary matrix M, a cyclic island is a region of 1s where the region encircles itself (horizontal, vertical and cross directions are allowed) Given a matrix M, Allowing neighbors to be in any of ...
2 votes
0 answers
66 views
Coin Change Recursive, memoization gone wrong
I'm trying to understand why first one fails and second works, all I'm doing is passing along coinTrack, call it redundant but why does it not work? It works without memoization, but on using ...
1 vote
0 answers
56 views
The principle of solving a problem through dynamic programming
I have the following task, but I don’t understand how I could solve it through dynamic programming or perhaps I need to solve it through graphs, could someone help me solve it? The frog Sandy likes ...
0 votes
0 answers
164 views
How to implement join order optimization using dynamic programming in Python?
I am working on a project to optimize SQL queries by determining the optimal join order using dynamic programming in Python. Context I am connecting to a PostgreSQL database and need to calculate the ...