Skip to content

Problem1 and Problem2 added#1532

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

Problem1 and Problem2 added#1532
megharaykar wants to merge 1 commit into
super30admin:masterfrom
megharaykar:master

Conversation

@megharaykar

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Least Falling Path Sum (Problem1.py)

It appears you have solved the wrong problem. The problem you were assigned was "Least Falling Path Sum", but your solution is for "Delete and Earn". Please double-check the problem statement and ensure you are solving the correct problem.

For "Least Falling Path Sum", you need to consider a dynamic programming approach that works on an n x n matrix. The problem requires finding the minimum sum of a falling path from the top row to the bottom row, where from each cell you can move to the cell directly below, diagonally left below, or diagonally right below.

Here are some pointers for solving the correct problem:

  1. You can use a DP table where dp[i][j] represents the minimum falling path sum starting from the first row to the cell (i, j).
  2. The recurrence relation would be:
    • For the first row (i=0), dp[0][j] = matrix[0][j]
    • For subsequent rows (i>0):
      dp[i][j] = matrix[i][j] + min(dp[i-1][j-1] if j>0, dp[i-1][j], dp[i-1][j+1] if j < n-1)
  3. The answer would be the minimum value in the last row of the DP table.

You can also optimize space by using only the previous row for calculations, reducing space complexity from O(n^2) to O(n).

Please revisit the problem statement and implement the solution accordingly. Always make sure you are solving the correct problem by reading the title and description carefully.

VERDICT: NEEDS_IMPROVEMENT


Delete and Earn (Problem2.py)

It appears there has been a mix-up in the problem. The code you submitted is for "Unique Paths", but the problem you were supposed to solve is "Delete and Earn".

For "Delete and Earn", the key insight is that when you choose to take a number, you cannot take its immediate neighbors (nums[i]-1 and nums[i]+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.
  2. Create an array arr where arr[i] is the total points you can get from all occurrences of i (i.e., frequency * i).
  3. Use dynamic programming where dp[i] represents the maximum points you can earn up to value i.
  4. The recurrence is: dp[i] = max(dp[i-1], arr[i] + dp[i-2]) for i>=2, with base cases dp[0] = arr[0] and dp[1] = max(arr[0], arr[1]).

You should implement this logic instead. Your current solutions for "Unique Paths" are well-structured and show a good progression from recursive to optimized DP, but they are not applicable here.

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