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

All Questions

1 vote
1 answer
19 views

Maximizing sum of signed numbers by not skipping more than one consecutive value: DP goes wrong

I am trying to solve this code challenge: A user maintains a list of negative and positive ratings for movies in a collection. The user wants to choose some subsequence of movies from the collection ...
R M's user avatar
  • 11
0 votes
1 answer
34 views

Performance Comparison Between Tabulation and Memoization for Dynamic Programming [closed]

I'm delving into dynamic programming and trying to understand the general performance differences between tabulation and memoization. Both techniques aim to optimize recursive algorithms by storing ...
Veer Pratap'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
9 views

why this code is giving error in solve_spo function but not in other function use . the solve_spo function is derived from the solve_tabu function

int solve_tabu(int N ,int arr[],int t){ vector<vector<int>> dp(t+1,vector<int>(N+1,0)); for(int i=0;i<=N;i++){ dp[0][i]=1; } for(...
GOVIND SINGH GURJAR 's user avatar
1 vote
0 answers
44 views

The principle of solving a problem through dynamic programming

I have the following task, but I don’t understand how I could solve it through dynamic programming or perhaps I need to solve it through graphs, could someone help me solve it? The frog Sandy likes ...
Oerlikon's user avatar
0 votes
2 answers
55 views

dynamic programming: (minimum days of not eating icecreams)

Minimum Days Not Eating Ice-cream Ram decides to eat ice-cream for N days. On each day the ice-cream shop can have chocolate flavour or mango flavour or both or none. The availability of ice-cream ...
Srinivasan A's user avatar
0 votes
1 answer
26 views

Number of hits in fibonacci using lru_cache

I am using functools.lru_cache to implement Fibonacci using memoization. But I do not understand the number of hits that my output generates. My code is as follows: @lru_cache(maxsize=8) def fib(n): ...
user23359931's user avatar
0 votes
0 answers
40 views

Dynamic Programming [Longest Palindromic Substring]

I solved this problem using recursion and memoization but struggled to come up with an iterative solution. Can someone help me to convert the below recursive solution into iterative solution with step-...
new Dawn's user avatar
0 votes
1 answer
195 views

sum max path of matrix using dynamic programming

Given a matrix mat[][], of dimensions N * N, I need to find the path from the top-left cell (0, 0) to the bottom-right cell (N – 1, N – 1) of the given matrix such that sum of the elements in the path ...
bara's user avatar
  • 3
0 votes
0 answers
39 views

My painting fence code is not giving correct output for large input [duplicate]

long long countWays(int n, int k){ // code here if(n==1) return k; long long a[n-1]; long long b[n-1]; // for n=2 a[0]=k; b[0]=k*(k-1); ...
Swadhin Ranjan Patra's user avatar
1 vote
2 answers
301 views

Getting stackoverflow error when I use for loop but if the same thing is done using an if block no error is produced [closed]

I was solving a DSA problem the language I'm using is java SE link:https://www.codingninjas.com/studio/problems/ninja-s-training_3621003 I know my solution is correct but for one of the test cases(I ...
Aries Ha's user avatar
-2 votes
2 answers
278 views

Wrong output with dynamic programming on Limited Subway Surfer challenge

I tried solving this code challenge using Dynamic Programming, but I do not get expected result. The "Limited Subway Surfer" challenge Nidhi has created an alternate version of Subway ...
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
0 votes
0 answers
36 views

I was trying to solve this question on GFG. Can anyone please tell me what is wrong with my code?

Geek's Journey You're provided with two arrays: "geeksTown" of length n - representing the heights of buildings in Geek's town "journey" of length m - representing the ...
Tejas x's user avatar
5 votes
1 answer
271 views

Is there any true general pattern to solve any dynamic programming problems?

I understand there is a general pattern to solve dynamic programming problems. Consists of: Identify Overlapping Subproblem by Breaking down the problem into smaller subproblems that are solved ...
silenok sweet's user avatar

15 30 50 per page
1
2 3 4 5
20