Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
165 views

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
154 views

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
55 views

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
89 views

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
102 views

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
26 views

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

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

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
102 views

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
154 views

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

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
131 views

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.6k
-3 votes
1 answer
129 views

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
66 views

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
56 views

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
0 votes
1 answer
182 views

I can cache an instance attribute like so: from dataclasses import dataclass from functools import cached_property @dataclass class Point: _x: float @cached_property def x(self): ...
Q42's user avatar
  • 23
2 votes
3 answers
159 views

I was going through a dp problem, there I have to initialize the matrix with default(-1) values for memoized solution. And felt the need. We can initialize the 1D array in java like this => Arrays....
Rushil Patel's user avatar
0 votes
2 answers
327 views

We are given an array of positive weights cost where cost[i] represents the cost of filling i + 1 kg's of oranges in a bag (0-based indexing). We need to find the minimum cost to buy exactly w kg's of ...
Learner's user avatar
  • 75
1 vote
1 answer
41 views

I'm doing https://leetcode.com/problems/longest-increasing-subsequence/ I know in theory that each index needs to be assigned a length but i'm having trouble coding it up using my iterative approach /*...
xqcccccccccc's user avatar
1 vote
1 answer
42 views

ConditionalWeakTable represents a thread-safe way to attach references to other references and not have to worry about garbage collection of the attached references. However, it can only be used with ...
cmeeren's user avatar
  • 4,230
0 votes
0 answers
35 views

I am trying to use SpatialFocus.MethodCache but with a static method rather than in an instance of a class. I am getting an error: 1>MSBUILD : warning : Fody/SpatialFocus.MethodCache: Class Test ...
Eugene's user avatar
  • 153
0 votes
1 answer
116 views

I wonder if it OK to define the Elements outside of the components. Just something like this const Element = <Component/> const App = () => { return <MemoizedParentComponent>{Element}&...
Nikita Monastyrskyi's user avatar
0 votes
0 answers
153 views

I'm encountering an issue with preserving state in a React component when client-side routing occurs. Specifically, I'm using the useState and useMemo hooks to manage and memoize the state of sorted ...
Ashfiquzzaman Sajal's user avatar
0 votes
0 answers
159 views

I am designing a ZIO service. And I have to use memoization in it's internal logic. How can I do that? For example, if a method (or all the methods) of a service require some kind of authorization ...
Uniqus's user avatar
  • 574
0 votes
1 answer
387 views

Streamlit's st.cache_resource decorator is key to speeding up streamlit apps. In functions like: @st.cache_resource def slow_function(inputA, input_b): ... return something it can speed up the ...
Myccha's user avatar
  • 1,068
0 votes
2 answers
54 views

I have a component that looks like this import { useState, useEffect, useMemo } from 'react' import Input from '~/components/Input' import Fuse from 'fuse.js' interface Props { data: any[] keys: ...
Trufa's user avatar
  • 40.9k
1 vote
1 answer
124 views

Background I recently learned that the fixed-point combinator makes it easy to define recursive functions without naming them. It is primarily used in functional programming languages (e.g. fix ...
Harumaki's user avatar
-2 votes
1 answer
80 views

Introduction I'm trying to understand the useCallback() hook in React and its role in solving function equality issues. I came across a blog post that discusses this concept, but I'm still unclear ...
volfcan's user avatar
  • 31
0 votes
2 answers
65 views

i am trying to understand react memo and i created a simple interface in my react native app. the app consists of two elements: MainApp.tsx -> controls the list of the user User.tsx -> displays ...
denistepp's user avatar
  • 540
0 votes
0 answers
20 views

const memoFactorial = () => { let cache = { 1: 1 } return function factorial(n) { console.log(cache) if (n in cache) { console.log('Fetching from cache:', n) return cache[n] ...
Renna Carver's user avatar
0 votes
1 answer
43 views

My case is very straightforward - everyone has this kind of hooks. It contains state and returns some method for operating this state. My question is why I sometimes get state variable (loadedPolys) ...
wra's user avatar
  • 515
0 votes
1 answer
85 views

The goal is to find the largest divisible subset. A divisible subset is a subset s.t. for every pair of elements i, j, either i is divisible by j or j is divisible by i. The general approach to solve ...
Alec's user avatar
  • 9,733
2 votes
0 answers
280 views

I saw one posting that is about 'how to prevent rerendering, and too much adding memoization'. The posting: https://d2.naver.com/helloworld/9223303 (it's written in korean, I'm not sure it has english ...
hololo's user avatar
  • 45
2 votes
1 answer
83 views

I need to write the following function: Write a function that takes in a target (int) and a list of ints. The function should return a list of any combination of elements that add up to the target, ...
CStudent's user avatar
  • 158
1 vote
1 answer
343 views

In my last commit, I degraded the performance of my React app (I introduced Context, and I learned that it interfers with Memoization). I would like to add tests that checks that a memoized component ...
H-H's user avatar
  • 476
1 vote
1 answer
50 views

I read that pyhton will recycle IDs, meaning that a new object can end up with the ID of one that previously existed and was distroyed. I also read about pickle: The pickle module keeps track of the ...
Philip Couling's user avatar
1 vote
1 answer
683 views

In React we have latest new function called cache so what should be different between cache and useMemo hook in react import {cache} from 'react';
Vishal Tanna's user avatar
  • 1,345
0 votes
0 answers
65 views

I am using following code to optimize the speed of the overall program execution. This program execution involves memoization. ( i.e. I am maintaining the results in an existing dictionary and using ...
Usman's user avatar
  • 2,900
0 votes
0 answers
143 views

Given a square grid of size N, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which ...
Elias El hachem's user avatar
1 vote
1 answer
1k views

Memoization is a programming technique where the results of expensive function calls are stored and reused, preventing redundant computations and improving performance. Sample Memoization import java....
Akiner Alkan's user avatar
  • 7,068
0 votes
1 answer
293 views

I am trying to solve this leetcode problem: https://leetcode.com/problems/minimum-falling-path-sum/description Given an n x n array of integers matrix, return the minimum sum of any falling path ...
Hemanth Annavarapu's user avatar
2 votes
1 answer
523 views

I would like to implement a revalidation endpoint in a Next project with the app router, so I think my options would be revalidatePath and revalidateTag. The data access I want revalidated works with ...
maja's user avatar
  • 830
1 vote
1 answer
2k views

I want to mock a React component that has been memoized. I'm using React 18.2 and Jest 29.7 with Typescript, in case that matters. I've tried several things but can't seem to find a way that works. ...
Tobias Wichtrey's user avatar
1 vote
2 answers
145 views

I want to memoize the return result of my function that take two int. i know i could convert the vector as a string like 1-2 but is there another way to do it ? I tried to set an array as a map but ...
rayankb92's user avatar
1 vote
0 answers
85 views

The problem statement from leetcode - https://leetcode.com/problems/knight-probability-in-chessboard/ Basically, knight starts from a given position and randomly picks 1 of 8 possible moves. It makes ...
tester test's user avatar
0 votes
0 answers
18 views

I have the following python code, def helper(nums, d, n, memo): if d == 0: return True if (d < 0 or n == 0): return False if memo[n][d] is not None: return memo[...
vz8's user avatar
  • 9
1 vote
2 answers
122 views

I have defined a custom continuous distribution, with implemented _pdf and _cdf methods. For these I need to compute expensive constants (given the parameters), namely the normalization constant for ...
ProodjePindakaas's user avatar
1 vote
1 answer
187 views

I'm doing this challenge: https://leetcode.com/problems/longest-common-subsequence/ I've tried a number of ways to debug my code, but I can't figure out what's wrong. Like in my head the way I ...
mfaani's user avatar
  • 37.1k
0 votes
0 answers
569 views

I am working on a DP problem to find longest stable subsequence, and I'm currently stuck with recovering the solution. Here is the problem statement I have tried the below solution, def computeLSS(a):...
stack underflow's user avatar
0 votes
1 answer
35 views

Consider 2 strings: a = "wxy" b = "mnop" z = "wmxnoyp" string z is a mixedstring if it is a combination of string a and b such that the length of string z is equal to ...
ABC123's user avatar
  • 31

1
2 3 4 5
31