Airport Limousine (Maximum Passengers Collected) (Also for Core/Database Intern :)
Updated
Problem statement
A taxi travels through a square matrix from (0, 0) to the railway station at (n - 1, n - 1), then returns to (0, 0).
Each cell has one of the following values:
0: an empty path cell1: a path cell containing one passenger-1: an obstruction that cannot be entered
On the outward trip, the taxi may move right or down. On the return trip, it may move left or up. Whenever the taxi enters a cell containing a passenger, that passenger is collected and the cell becomes empty.
If no valid route exists between the endpoints, no passenger can be collected. Otherwise, maximize the number of distinct passengers collected over the outward and return trips.
Complete maximumPassengersCollected with int mat[n][n].
Returns: int, the maximum number of passengers that can be collected.
Function
maximumPassengersCollected(mat: int[][]) → intExamples
Example 1
mat = [[0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]return = 2The taxi can collect both passengers by taking the outward route along the top row and right edge, then returning along the bottom row and left edge. The maximum is 2.
Example 2
mat = [[0, 1, -1], [1, 0, -1], [1, 1, 1]]return = 5A legal round trip is (0,0) → (0,1) → (1,1) → (2,1) → (2,2) → (2,1) → (2,0) → (1,0) → (0,0). It avoids both obstruction cells and collects all five passengers, so the answer is 5.
Constraints
1 <= n <= 100-1 <= mat[i][j] <= 1
More Snowflake interview questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
- Safest Shortest Path Through a GridOA · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Cherry PickupInfosys · OAInfosys interview questions
- Minimum Cost Path with TeleportationsAmazon · OA
- Minimum Starting Health in a GridIntuit · OAIntuit interview questions
- Largest Two Non-Overlapping Buildable SquaresAmerican Express · OAAmerican Express interview questions
- Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
- Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
- Increasing Paths, part 2Hudson River Trading · OAHudson River Trading interview questions
- Timed Coin Collection in a 2×N GridAtlassian · OAAtlassian interview questions
- Maximum Sum RectangleDeloitte · OADeloitte interview questions
- Longest Increasing Path in a MatrixNutanix · OANutanix interview questions