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

All Questions

1 vote
1 answer
21 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
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 ...
Lesserrafim's user avatar
-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 ...
bugdebug's user avatar
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 ...
Amir Hossein's user avatar
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)....
Lupin's user avatar
  • 59
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 ...
AKHIL's user avatar
  • 5
-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 ...
ABGR's user avatar
  • 5,003
1 vote
1 answer
140 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
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
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 ...
Mason Kane's user avatar
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 ...
Karthikeyan's user avatar
-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 ...
Lishant's user avatar
  • 43
-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(...
Andreas Hunter's user avatar
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 ...
ABGR's user avatar
  • 5,003
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

15 30 50 per page
1
2 3 4 5
220