Skip to content

[minFallingPathSum + deleteAndEarn]#1524

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

[minFallingPathSum + deleteAndEarn]#1524
takchiks wants to merge 1 commit into
super30admin:masterfrom
takchiks:master

Conversation

@takchiks

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Your solution for minFallingPathSum is excellent. You have implemented an efficient dynamic programming solution with optimal time and space complexity. The code is clean and well-commented. However, note that the problem only requires the minFallingPathSum method. The inclusion of the deleteAndEarn method suggests that you might have been working on multiple problems and accidentally included it. In a real interview or submission, ensure that you only submit the relevant code for the problem at hand.

One minor improvement: In the inner loop, you are calculating minAbove by comparing the current prev[j] with its left and right neighbors. You can initialize minAbove to prev[j] and then update it with the neighbors if they exist. This is exactly what you did, and it is correct. Alternatively, you could use:

int minAbove = prev[j];
if (j > 0) minAbove = Math.min(minAbove, prev[j-1]);
if (j < n-1) minAbove = Math.min(minAbove, prev[j+1]);

which is clear and efficient.

Overall, great job on the main problem! Just be cautious to not include extraneous code.

@super30admin

Copy link
Copy Markdown
Owner

Your solution for the "Least Falling Path Sum" problem is excellent. You have implemented an efficient dynamic programming approach with O(n^2) time and O(n) space, which is optimal. The code is clean and well-commented. However, note that the problem only requires one solution, so including an unrelated method (like deleteAndEarn) might be confusing for someone reading the code. It's better to separate solutions for different problems into different files or classes. Keep up the good work!

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