Description
Solutions
Submission
Airport Limousine (Maximum Passengers Collected) (Also for Core/Database Intern :)
🤘 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:
Returns
int
: maximum number of passengers that can be collected.
Example 1:
Input: mat = [[0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
Output: 2
Explanation:The driver can contain a maximum of 2 passengers by taking the following path: (0,0) -> (0,1) -> (0,2) -> (0,3) -> (1,3) -> (2,3) -> (3,3) -> (3,2) -> (3,1) -> (3,0) -> (2,0) -> (1,0) -> (0,0)
Example 2:
Input: mat = [[0, 1, -1], [1, 0, -1], [1, 1, 1]]
Output: 5
Explanation:The driver can contain a maximum of 5 passengers by taking the following path: (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (2,1) -> (2,0) -> (1,0) -> (0,0)
Constraints:
1 <= n <= 100
-1 <= mat[i][j] <= 1
Related Problems
Testcase
Result
Case 1
input:
output: