All Questions
Tagged with dynamic-programming recursion
750
questions
2
votes
0
answers
48
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 ...
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....
0
votes
1
answer
20
views
Recusion: does the order of safety checks vs base cases matter?
I am learning dynamic programming, and I have observed when creating recursive code, sometimes we check out-of-bounds conditions first then check other base cases, and sometimes we check the other ...
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 ...
-2
votes
1
answer
115
views
Coin Change: for loop analysis
I am trying to comprehend the problem which has different wording but I figured it is similar to coin change problem
Question:
Two friends are playing a game with a book numbered from 1 to 9. The game ...
3
votes
1
answer
67
views
Return correct value at each iteration- dynamic programming
The problem goes like this:
Geek is going for n day training program. He can perform any one of these three activities Running, Fighting, and Learning Practice. Each activity has some point on each ...
2
votes
3
answers
208
views
Maximum Sum Without Skipping Two Contiguous Elements
The task is to find the maximum sum of a subsequence of integers from a given list. The subsequence must follow two conditions:
It must be contiguous, meaning the selected elements are in consecutive ...
0
votes
2
answers
202
views
Increasing Tripplet Subsequence
I was attempting the Increasing Triplet Subsequence problem on leetcode.com
I started off with a brute force approach but it ran into time out issues but passing almost all testcases. The following is ...
0
votes
2
answers
73
views
How to convert this top down dp to bottom up dp
Given two arrays a and b of positive integers of size n and m where n >= m, the task is to maximize the dot product by inserting zeros in the second array but you cannot disturb the order of ...
0
votes
1
answer
44
views
Leetcode 1255-recursion and backtracking
I dont quite understand why have we used .clone() method when we have a second for loop to restore the letterCount.And when i'm runnig this code without .clone() method its giving me the wrong answer? ...
1
vote
1
answer
129
views
Is there a optimal solution for Jump Game Problem using C programming
PROBLEM DESCRIPTION
You are given an integer array. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return ...
0
votes
1
answer
23
views
Issue solving DFS Flood Fill problem while iterating through branching options
I am learning Dynamic Programming and am trying to solve the Leet Code Flood Fill problem.
I came up with this solution, but it doesn't recurse correctly through all the possible moves.
Given the ...
0
votes
1
answer
150
views
Trouble Solving Maximum Product Subarray
I am trying to solve LeetCode problem 152. Maximum Product Subarray:
Given an integer array nums, find a subarray* that has the largest product, and return the product.
The test cases are generated ...
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 ...
1
vote
1
answer
79
views
Dynamic Programming problems with coins
There is an array of 𝑛 coins with values 𝐶 = [𝑐1, 𝑐2, … , 𝑐𝑛]. The prices
are positive integers and repetitions are allowed. For example, one
possible sequence of coins is as follows: 𝐶7 = [5, ...