Lightest Hiking Route
Easy · 2-D & String DP · about 15 min
A hiking map is a grid of numbers: grid[r][c] is the effort needed to cross that square. You start in the top-left square and finish in the bottom-right one, moving only right or down. The effort of a route is the sum of every square it crosses, including the start and the finish.
Return the smallest possible effort.
1 <= rows, cols <= 100, each effort is between 0 and 100.
Example:
lightest_route([[1, 3, 1], [1, 5, 1], [4, 2, 1]]) → 7 (1 → 3 → 1 → 1 → 1)
Hints
- You can only arrive at a square from above or from the left.
- Keep the cheapest effort to reach every square, and add the square's own effort.
- The top row and left column have only one way in, so fill them first.
Learn the pattern first: the 2-D & String DP lesson.
More 2-D & String DP problems
- Warehouse Robot Routes (Easy)
- Shared Travel Order (Medium)
- Longest Mirror Piece (Medium)
- Two Equal Delivery Vans (Medium)
- Plus or Minus Ledger (Medium)
- Fill the Cargo Bay Exactly (Medium)
- Ways to Pay the Toll (Medium)
- Priced Spelling Fix (Hard)
- Hidden Copies in a Log (Hard)
- File Filter Wildcards (Hard)
- Label Printer Tiles (Hard)