Skip to content

Complete DP-3 - #1556

Open
satish-paraddi wants to merge 2 commits into
super30admin:masterfrom
satish-paraddi:master
Open

satish-paraddi wants to merge 2 commits into
super30admin:masterfrom
satish-paraddi:master

Conversation

@satish-paraddi

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Minimum Falling Path Sum (Problem_1.py)

It appears you submitted the solution for the wrong problem. The file is named Problem_1.py and contains a deleteAndEarn method, which solves LeetCode 740 "Delete and Earn," not LeetCode 931 "Minimum Falling Path Sum."

To correct this:

  1. Re-read the problem carefully: The input is a 2D matrix (n×n), and you need to find the minimum sum path from top to bottom where each step moves to one of three positions in the next row.
  2. Approach: Use bottom-up dynamic programming. Create a DP array where dp[i][j] represents the minimum falling path sum ending at cell (i, j). For each cell, dp[i][j] = matrix[i][j] + min(dp[i-1][j-1], dp[i-1][j], dp[i-1][j+1]) (handling boundary cases).
  3. Answer: Return the minimum value in the last row of the DP array.
  4. Time complexity target: O(n²) for an optimal solution.

Please resubmit with the correct solution for "Minimum Falling Path Sum."

VERDICT: NEEDS_IMPROVEMENT


Delete and Earn (Problem_2.py)

It appears that you have submitted a solution for a different problem ("Minimum Falling Path Sum") instead of the assigned problem ("Delete and Earn").

To correctly solve "Delete and Earn":

  1. Understand the problem: You need to pick numbers from an array, earn points equal to the picked number, and then all occurrences of num-1 and num+1 are also deleted.
  2. Key insight: This problem is equivalent to the "House Robber" problem. If you create an array where arr[i] represents the total points you would earn by picking all occurrences of number i, then you need to find the maximum sum of non-adjacent elements in this array.
  3. Approach:
    • First, find the maximum value in nums to determine the size of your counting array.
    • Create an array points where points[i] = sum of all is in nums.
    • Use DP: dp[i] = max(dp[i-1], points[i] + dp[i-2]).
  4. Test your solution: Make sure your function signature matches deleteAndEarn(nums: List[int]) -> int.

Please re-implement the solution for the correct 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