All Questions
Tagged with algorithm dynamic-programming
3,295
questions
3
votes
2
answers
105
views
A more efficient algorithm in finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
-1
votes
2
answers
96
views
Flip consecutive zeroes to ones in k operations to have maximum number of ones, find the maximum number of ones
You are given a binary string made of 0 and 1, and a value k which represents number of operations. You can flip consecutive 0s in each operation to 1s. Find the maximum number of 1s after k ...
1
vote
4
answers
81
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 ...
1
vote
1
answer
94
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)....
0
votes
2
answers
62
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 ...
-1
votes
1
answer
48
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 ...
1
vote
1
answer
139
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 ...
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 ...
4
votes
3
answers
247
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 ...
1
vote
2
answers
129
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 ...
-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 ...
-2
votes
2
answers
60
views
How to find the optimal products with the lowest price amount with the highest quantity?
I tried to write a function for myself but it somehow incorrectly outputs the final result:
function findOptimalProducts(products, budget) {
const getPrice = (priceString) => parseFloat(...
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 ...
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 ...
0
votes
0
answers
33
views
How can longest strictly increasing subarray problem have overlapping subproblems
In the longest strictly increasing subarray problem, we have an array A, and we need to find the longest subarray such that in that subarray S, S[k]>S[k-1].
Since we can divide the array A into ...