Skip to content

1937. Maximum Number of Points with Cost #335

Answered by topugit
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We can break down the solution into several steps:

Step 1: Define the DP Array

We will use a 2D array dp where dp[i][j] represents the maximum points we can achieve by selecting the cell at row i and column j.

Step 2: Initialize the DP Array

Initialize the first row of dp to be the same as the first row of points since there are no previous rows to subtract the cost.

Step 3: Calculate DP Values for Each Row

For each subsequent row, we calculate the maximum possible points for each column considering the costs of switching from the previous row.

To efficiently calculate the transition from row i-1 to row i, we can use two auxiliary arrays left and right:

  • left[j] will store the maximum val…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Aug 17, 2024
Maintainer Author

@topugit
Comment options

topugit Aug 17, 2024
Collaborator

Answer selected by mah-shamim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants