Airport Limousine (Maximum Passengers Collected) (Also for Core/Database Intern :)
A taxi can take multiple passengers to the railway station at the same time. On the way back to the starting point, the taxi driver may pick up additional passengers for his next trip to the airport. A map of passenger location has been created, represented as a square matrix.
The matrix is filled with cells, and each cell will have an integer value as follows:
The rules of motion of taxi are as follows:
For example, consider the following grid:
Start at the top left corner. Move right one, collecting a rider. move down one to the airport. Cell (1, 0) is blocked, so the return path is the reversed of the path to the airport. All paths have been explored, and 1 rider was collected.
Returns
int: maximum number of passengers that can be collected.
🌿 𖡼𖤣𖥧𖡼𓋼𖤣𖥧𓋼𓍊, Credit to robotᥫ᭡.🌿
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 100-1 <= mat[i][j] <= 1