Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We can try to build the answer in a bottom-up fashion, starting from the smallest values and increasing to the larger values.
Going through the values in sorted order, we can store the maximum path we have seen so far for a row/column.
When we are at a cell, we check its row and column to find out the best previous smaller value that we’ve got so far, and we use it to increment the current value of the row and column.