Skip to main content

Questions tagged [dynamic-programming]

Dynamic programming is an algorithmic technique for efficiently solving problems which have recursive structure with many overlapping subproblems. Do NOT use this tag for general "dynamic" behavior in code.

dynamic-programming
-9 votes
0 answers
54 views

how can i find the minimum sub array? [closed]

The candies supermarket sells m different types of candies and has n consecutive boxes, each box contains a single type of candy, you are allowed to buy only some contiguous boxes of candies (i.e. the ...
Abood Elean's user avatar
1 vote
4 answers
72 views

The minimum size of substrings for the presence of at least one character

i have a question that want the minimum length of k that in each consecutive substring of a string with length k, There must be at least one common character. for example if s="abcaca" for k ...
Amir Hossein's user avatar
1 vote
1 answer
86 views

Single Source - Single Destination Shortest Path (DFS + DP) - Time complexity?

Context: I want to write an algorithm for finding the shortest(least cost) path from a fixed source to a fixed destination node in a weighted directed graph with non negative weights (can have cycles)....
Lupin's user avatar
  • 59
0 votes
2 answers
60 views

Understanding dynamic programming timeouts with 2 different solutions

The problem is from leetcode (link - https://leetcode.com/problems/the-number-of-ways-to-make-the-sum/description/ ) You have an infinite number of coins with values 1, 2, and 6, and only 2 coins with ...
AKHIL's user avatar
  • 5
2 votes
0 answers
46 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 ...
user2643191's user avatar
-1 votes
1 answer
45 views

Coin Change II : To take a value or not to

The problem goes like this: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of ...
ABGR's user avatar
  • 5,005
2 votes
4 answers
99 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
1 answer
19 views

order of writing base cases in recursion how to figure out based on quesion

I am learning dynamic programming I have observed when solving recursive code soemtimes we check out of bound conditiosns first then check other base cases and sometimes it is we check the other bases ...
Silent Geek's user avatar
1 vote
1 answer
98 views

Asteroid Mining - Dynamic Programming problem

I was given the following assignment: There is n gram of mineral to be dug up on a certain asteroid. At the beginning there is only one robot at our disposal. Each robot can do one of two activities ...
PK96's user avatar
  • 51
0 votes
2 answers
92 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
4 votes
3 answers
239 views

Minimum Cell Changes to Ensure Unique Numbers in Each Row and Column of an n×n Table

We have an n×n table, and in each cell of the table, there is a number from 1 to 2n. We want to change the numbers in some of the cells and replace them with other numbers from 1 to 2n such that in ...
Mason Kane's user avatar
1 vote
1 answer
60 views

Why backtracking is giving wrong results in case of 1st question and correct results for 2nd. Leetcode #322 #78 respectively

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make ...
Ashna kohli's user avatar
1 vote
2 answers
125 views

Dynamic programming partition array to find minimum difference fails for negative numbers

I am trying to solve the problem it works for positive integer arrays but fails for negative test cases. How to handle the below test case? You are given an integer array nums of 2 * n integers. You ...
Karthikeyan's user avatar
0 votes
0 answers
8 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
0 votes
0 answers
11 views

DynamicProgramming Proble,

Problem Link :https://www.geeksforgeeks.org/problems/count-numbers-containing-43022/1 Problem Description : You are given a number n, Return the count of total numbers from 1 to n containing 4 as a ...
LOKESH's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
380