Gamified challenge · Dijkstra with a custom cost
heights[r][c] is the height of the ground at row r, column c. You start at the top-left cell and must reach the bottom-right cell, moving up, down, left or right one cell at a time.
A step's effort is the absolute height difference between the two cells, and a route's effort is its largest single step. Write minEffort(heights) that returns the smallest effort of any route. A 1×1 map needs no steps: 0.
Example: [[1,2,2],[3,8,2],[5,3,5]] answers 2: the route 1 → 3 → 5 → 3 → 5 down the left side and along the bottom never changes height by more than 2.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google