A hiking app shows a grid of terrain heights. A hiker starts at the top-left cell, must reach the bottom-right cell, and moves up, down, left, or right. The effort of a route is the largest height change between any two consecutive cells on it.
Write smoothestRoute(heights) that returns the smallest effort of any route.
Input: heights = [[1,2,4],[3,8,5],[5,4,6]] Output: 2
Route 1 → 2 → 4 → 5 → 6 along the top and right edges has its biggest step from 2 to 4. Every route has a step of at least 2.
Input: heights = [[7]] Output: 0
The start is the end, so no steps are taken.
1 <= heights.length, heights[i].length <= 2001 <= heights[i][j] <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #461 Smoothest Route Across a Heightmap. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.