Skip to content

Done dp-3#1534

Open
sainathek1999 wants to merge 1 commit into
super30admin:masterfrom
sainathek1999:master
Open

Done dp-3#1534
sainathek1999 wants to merge 1 commit into
super30admin:masterfrom
sainathek1999:master

Conversation

@sainathek1999

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Least Falling Path Sum (problem1.java)

It appears there has been a mix-up in the problem you are solving. The problem you are required to solve is "Least Falling Path Sum", which involves finding the minimum sum of a falling path through a matrix. However, your solution is for "Delete and Earn", which is a different problem entirely.

For the "Least Falling Path Sum" problem, you should consider using dynamic programming to build up the solution from the bottom row to the top. The reference solution provided uses a recursive approach with memoization (though it is not shown with memoization, it would be necessary to avoid exponential time complexity). Alternatively, you can use iterative DP to compute the minimum falling path sum efficiently.

Here are some steps to guide you for the correct problem:

  1. Initialize a DP table (or use the input matrix itself) to store the minimum falling path sum starting from each cell.
  2. Start from the second last row and move upwards. For each cell, update its value by adding the current value to the minimum of the three possible next cells (down, down-left, down-right).
  3. The answer will be the minimum value in the first row after processing.

Time complexity should be O(n^2) and space complexity O(n^2) or O(n) if optimized.

Please ensure you are solving the correct problem and review the problem statement carefully.

VERDICT: NEEDS_IMPROVEMENT


Delete and Earn (problem2.java)

It seems there has been a misunderstanding. The problem you were asked to solve is "Delete and Earn", but your solution is for "Minimum Falling Path Sum". Please ensure you are solving the correct problem.

For the "Delete and Earn" problem, the key insight is to recognize that when you choose to earn points from a number, you cannot earn from its immediate neighbors (num-1 and num+1). This is similar to the "House Robber" problem, where you cannot rob adjacent houses.

Here's a suggested approach for "Delete and Earn":

  1. Find the maximum value in the array to determine the range of numbers.
  2. Create an array arr where arr[i] is the total points you can get from all occurrences of i (i.e., count[i] * i).
  3. Then, you can use dynamic programming similar to "House Robber":
    • dp[i] = max(dp[i-1], arr[i] + dp[i-2])
    • This is because if you take the value i, you cannot take i-1, but you can take i-2.

Your current solution does not address this problem. Please rework your solution to handle the "Delete and Earn" problem.

VERDICT: NEEDS_IMPROVEMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants