Phase 1: Pick an order for the cells

Pick an order for the cells

You have a matrix. From any cell, you can step to an UP / DOWN / LEFT / RIGHT neighbor if its value is strictly greater. Find the longest such path (count of cells visited).

Your instinct says: fill a table. Before we write a line of code, pick the fill order you would use. Row by row? Column by column? Something else?

FIG. 1 — COMMIT TO AN ORDERING — RUN IT
Fill orderings to try
Pick a fill ordering to commit.