Gamified challenge · Grid DP
A field is scattered with coins. You start on the top-left cell and must reach the bottom-right one, moving only right or down. coins[r][c] is the number of coins on a cell, or -1 for a rock you can't step on. The start and finish are never rocks, and a path always exists.
Write bestPath(coins) (best_path in Python) that returns your moves as a string of R and D collecting the most coins (the start and finish cells count). For [[1, 3, 1], [1, -1, 1], [4, 2, 1]] that's "DDRR", which collects 9.
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