Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

2 votes
4 answers
101 views

Is there a way initialize a matrix(2D array) with some default values(-1)

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

Dynamic Programming - Minimum cost to fill given weight in a bag

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
  • 29
0 votes
0 answers
11 views

Discrepancy in Recursive and Memoized Knapsack Solution

I'm currently working on a knapsack problem and have implemented both a recursive solution without memoization and a memoized version. Surprisingly, the recursive solution is giving me the correct ...
Pall Nikhil's user avatar
0 votes
1 answer
73 views

How is it possible to memoize longest divisible subset using only the length (and end position)?

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,226
2 votes
1 answer
52 views

Issue with Memoization in Recursive Function for Finding Combinations Summing to Target

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
  • 156
0 votes
0 answers
90 views

Minimum Cost Path Recursion - Memoization

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

Why Is It Called Memoization?

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
  • 6,732
0 votes
0 answers
27 views

Eliminating Recursion stack space

When we convert a recursion to memoization we reduce time complexity but increase space complexity (eg: fibonacci series dp problem) but we can get rid of recursive stack space by tabulation which is ...
hell_coder's user avatar
0 votes
1 answer
206 views

LeetCode - Minimum Falling Path Sum - question on memoization

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
1 vote
0 answers
75 views

Why is this solution to Knight probability in chessboard wrong?

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
1 vote
1 answer
125 views

Issue with implementation of longest common subsequence

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
  • 35.5k
0 votes
0 answers
276 views

Longest Stable Subsequence - Recover solution from memo table

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
1 vote
1 answer
150 views

DP array 0th element is initialized as 1 instead of 0

I encountered the LeetCode climbStairs problem: You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ...
Hari Prasad's user avatar
1 vote
0 answers
83 views

Dynamic programming with memoization on the rob house problem

This is my problem I'm working on: " You are a professional robber planning to rob houses along a street. The houses are numbered 0, 1, 2, ..., and you my assume that the number of houses is at ...
GaNk1n1t's user avatar
-1 votes
1 answer
306 views

"Coin change 2": Why is this dynamic programming implementation not efficient enough? [closed]

I am working on a LeetCode problem, 518. Coin Change II: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. ...
Paurab Bhattacharjee's user avatar

15 30 50 per page
1
2 3 4 5
21