Counting the best paths

Write code · Challenge · §10.3 Two-dimensional grid tables

The map of a live-stream mini game is a grid with a number of hearts (possibly 0) on each cell. hearts[i][j] is the number of hearts on cell j from the left in row i from the top. 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, collecting the hearts on every cell it passes through, including the starting cell and the goal cell. Complete the function solution, which returns the number of paths that collect the most hearts. Two paths are different if at least one cell they pass through is different. If several paths collect that largest number of hearts, count all of them. If the map has only one cell, there is one path that does not move.

Function

solution(hearts)

Constraints

Examples

heartsresult
[[1, 2], [3, 1]]1
[[2, 2, 9], [2, 6, 2], [1, 9, 3]]2

Starter code

def solution(hearts):
    answer = 0
    return answer

Solve 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.