Leetcode Problem 2713. Maximum Strictly Increasing Cells in a Matrix

2713. Maximum Strictly Increasing Cells in a Matrix

Leetcode Solutions

DP with maps, clean C++

  1. Flatten the matrix into a list of tuples containing the cell value and its coordinates (i, j).
  2. Sort the list of tuples based on the cell values in ascending order.
  3. Initialize two maps, one for rows and one for columns, to keep track of the maximum steps for each unique value.
  4. Iterate over the sorted list of tuples.
  5. For each tuple, calculate the current maximum steps by looking up the previous maximum steps in the row and column maps.
  6. Update the current cell's DP value to the calculated maximum steps plus one.
  7. Update the row and column maps with the new maximum steps for the current value.
  8. Keep track of the overall maximum number of steps encountered during the iteration.
  9. Return the overall maximum as the result.
UML Thumbnail

Beats%, no Binary Search or map

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...