Path with the highest score
Write code · Medium · §10.3 Two-dimensional grid tables
The map of a live-stream mini game is a grid, and each cell has a score. scores[i][j] is the score of cell j from the left in row i from the top, and trap cells have negative scores. Rows and columns are numbered from 0.
The character starts at the top-left cell and moves one cell at a time, only right or down, until it reaches the bottom-right cell, adding up the scores of all the cells it passes through, including the starting cell and the goal cell. Complete the function solution, which returns the largest total the character can collect. The answer may be negative.
Function
solution(scores)
Constraints
- The length of
scores(the number of rows) is from 1 to 100. - Every element of
scoresis a list of the same length (the number of cells in a row), from 1 to 100. - Each score is an integer from -100 to 100.
Examples
| scores | result |
|---|---|
[[1, 3, -2], [2, -4, 5], [0, 1, 2]] | 9 |
[[2, -1], [-3, 4]] | 5 |
Starter code
def solution(scores):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.