Skip to main content

All Questions

0 votes
0 answers
38 views

Valid Parenthesis String, Recursion with memoization to DP

How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution? The code is working but I want to improve it. The challenge I am facing is ...
Elias El hachem's user avatar
-1 votes
3 answers
169 views

Why isn't my method working for finding value of Fibonacci sequence for nth term?

I am trying to find the value of a Fibonacci sequence given an integer N, representing the nth term using an ArrayList (my logic is that because ArrayList are dynamic and can resize no matter what ...
websterweb40's user avatar
1 vote
1 answer
94 views

Max product non-intersection paths in tree

Question: Given an undirected tree with N nodes ( 2 <= N <= 100,000 ) and N-1 edges, how can I find two non-intersecting paths with maximum product? Example: 6 1-2 2-3 2-4 5-4 6-4 Answer: 4 ...
Aibar's user avatar
  • 11
0 votes
1 answer
299 views

Effective hiking - dynamic programming

I got the following question today, and solved it suboptimally. I wanted to get some help how to get this to the most optimal solution: The question is; A hiker needs to complete a lit of trails on ...
Bober02's user avatar
  • 15.4k
2 votes
2 answers
432 views

Extra characters in a string | LeetCode 2707

I am stuck while solving todays daily Leetcode problem and I'm asking for your guys' help. Here is the task: You are given a 0-indexed string s and a dictionary of words dictionary. You have to break ...
Homie_Tomie's user avatar
2 votes
2 answers
126 views

Number of jumps to reach the end (with updates)

We are given N squares number 0 to N - 1. Each square has target jump square J[i] (which must be at a larger index). At square i, you can only jump to square J[i]. If J[i] is past the last square, ...
user23274861's user avatar
-1 votes
2 answers
507 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
3 answers
132 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
73 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
191 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
69 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
868 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
1 vote
0 answers
39 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, even ...
Suryanarayanan's user avatar
0 votes
2 answers
721 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
1 answer
57 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

15 30 50 per page
1
2 3 4 5
38