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

All Questions

-2 votes
0 answers
32 views

Dynamic Programming for Minimum Operations to Equalize Arrays - Incorrect Results

I'm trying to solve a problem where we need to find the minimum number of operations required to make two integer arrays nums and target (same length) equal. In one operation, we can select a subarray ...
Android Developer'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
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....
Rushil Patel's user avatar
1 vote
1 answer
62 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
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
-4 votes
1 answer
64 views

Why is my code giving wrong answer when using 2d ArrayList and passing when using 2d arrays?

Here is the DP question, Given a ‘N’ * ’M’ maze with obstacles, count and return the number of unique paths to reach the right-bottom cell from the top-left cell. A cell in the given maze has a value '...
Anonymous's user avatar
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 ...
Vahaid Sk's user avatar
0 votes
0 answers
19 views

dynamic programming min path grid sum

"I recently found a frustrating error in my code. I have two solutions for finding the minimum path sum using dynamic programming (DP). The first solution, which I wrote, doesn't seem to work, ...
Suryanarayanan's user avatar
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 ...
Spindoctor's user avatar
0 votes
0 answers
57 views

Algorithm to split basket optimally

I have my own personal project and I got stuck while writing BasketSplitter class. My input data is in json format and looks as follows [ "Steak (300g)", "Carrots (1kg)", "...
fojok's user avatar
  • 11
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? ...
jonshrey's user avatar
0 votes
0 answers
11 views

Discrepancy in Recursive and Memoized Knapsack Solution

I'm currently working on a knapsack problem and have implemented both a recursive solution without memoization and a memoized version. Surprisingly, the recursive solution is giving me the correct ...
Pall Nikhil'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
0 answers
90 views

Minimum Cost Path Recursion - Memoization

Given a square grid of size N, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which ...
Elias El hachem's user avatar
0 votes
0 answers
57 views

How to optimize recursive dp solution to Buy and Sell stocks 3 problem?

I am trying to solve this problem - https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii I have the following code- class Solution { Map<State, int[][]> dp; enum State { ...
tester test's user avatar

15 30 50 per page
1
2 3 4 5
38