Skip to main content
3 votes
2 answers
158 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 = ...
Alfy B's user avatar
  • 167
0 votes
1 answer
149 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 ...
Tom Huntington's user avatar
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 ...
Elias El hachem's user avatar
0 votes
2 answers
84 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 ...
magrega's user avatar
  • 263
2 votes
2 answers
92 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 ...
kiwikodes's user avatar
  • 774
0 votes
0 answers
23 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 ...
Alius's user avatar
  • 1
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 = ...
Mohamed Samir's user avatar
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]...
figs_and_nuts's user avatar
1 vote
1 answer
99 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 ...
sonu's user avatar
  • 11
0 votes
1 answer
143 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, ...
souparno majumder's user avatar
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++) { ...
Shreshth Sharma's user avatar
2 votes
0 answers
127 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] ...
qwr's user avatar
  • 11.5k
-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(...
heman's user avatar
  • 3
3 votes
0 answers
62 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 ...
Bharadwaj Dasavaram's user avatar
0 votes
1 answer
51 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 ...
physicsuser's user avatar

15 30 50 per page
1
2 3 4 5
103