0 out of 464 challenges solved
Given a square matrix of size `N x N` represented as a list of lists, where each cell contains a specific cost, find the path from the top-left cell to the bottom-right cell that has the maximum average cost. You can only move right or down at each step. The average is computed as the total cost of the path divided by the number of cells visited. #### Example ```python [main.nopy] matrix = [ [1, 2, 3], [6, 5, 4], [7, 3, 9] ] result = max_average_path(matrix) print(result) # Output: 5.2 ``` #### Constraints - The matrix will always be square (N x N) with `N >= 1`. - All elements in the matrix are integers. Write a function `max_average_path(matrix)` that returns the maximum average of any valid path.
def max_average_path(matrix): """ Calculate the maximum average path in a square matrix. Args: matrix (list of list of int): The square matrix of costs. Returns: float: The maximum average of any valid path. """ # Placeholder for the solution pass