1,531 questions
3 votes
2 answers
165 views
Use of !! in memoization
When looking up memoization in Haskell, I found this bit of code: memoized_fib :: Int -> Integer memoized_fib = (map fib [0 ..] !!) where fib 0 = 0 fib 1 = 1 fib n = ...
0 votes
1 answer
154 views
Memoize function repeatedly called with same arguments?
I have a mathematical function called in render loop (240Hz). It's a function of some (atomic) state that very rarely changes. It calls 3 times to std::log, twice to std::sqrt, once to std::sin. When ...
0 votes
0 answers
52 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 ...
0 votes
2 answers
89 views
Flattening an array causes UI freeze
I have an app with cards. Cards are fetched with useInfiniteQuery from React Query. I fetch new card each time I reach the end of the list. Backend sends offset and limit based responses of this ...
2 votes
2 answers
102 views
How to avoid re-render in Redux based on the outputs of .filter()?
I have a simple scenario in which I want to access my store.entities, but only those which are active. I understand the following is bad because a new reference is given each time: const ...
0 votes
0 answers
26 views
I'm using this memoized dropdown component, which seems to close due to a re-render when the child text input box component inside changes
I'm stuck on this problem where I memoized the Dropdown component because it was causing infinite re-renders when I selected something from the dropdown. Now I'm facing an issue where everytime I ...
0 votes
1 answer
105 views
Storing the recursive call result in a variable leads to incorrect calculation in a DP memoized solution
Just by using the commented code instead of making the recursive calls inside the max function, leads to incorrect result particularly with the following test case int main() { Solution obj = ...
1 vote
2 answers
163 views
What is the time complexity of the following algorithm and is there any optimization I can do?
Problem: Given an array that sums to 0, find the maximum number of partitions of it such that all of them sum up to 0 individually. Example: input: [-2, 4, -3, 5, -4] output: 2 (which are [[5, -2, -3]...
1 vote
1 answer
102 views
How can I memoize a JavaScript function that accepts multiple arguments, including objects?
I’m trying to improve the performance of a computationally expensive JavaScript function by memoizing it. The function accepts multiple arguments, including objects. Here's an example: function ...
0 votes
1 answer
151 views
Why is this DFS + Memoization solution for selecting indices in two arrays too slow while a similar approach is more efficient?
I was solving LeetCode problem 3290. Maximum Multiplication Score: You are given an integer array a of size 4 and another integer array b of size at least 4. You need to choose 4 indices i0, i1, i2, ...
0 votes
1 answer
58 views
3-D DP VS 2-D DP, can't seem to figure out why my code can't be memoized
class Solution { public: int countNeighborhoods(const vector<int>& houses) { int neighborhoods = 0; int m = houses.size(); for (int i = 0; i < m; i++) { ...
2 votes
0 answers
131 views
Function memoization, passing around precomputed values [closed]
I have a function like this in my library, which depends on a large subset of the inputs being pre-calculated: @cache def f(n, precompute): if n < len(precompute): return precompute[n] ...
-3 votes
1 answer
129 views
Adding DP to 0/1 knapsack
Here are the two different ways of solving 0/1 knapsack using recursion. #include<bits/stdc++.h> using namespace std; #define vi vector<int> #define vb vector<bool> long long solve1(...
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
1 answer
56 views
createSelector difference for the memoization values
I have the following problem , in the code I found many places where the createSelector was not implemented correctly and i want to change it to imporve performance in the frontend. Originally the ...