Max Reachable Delivery Points
Delhivery operates a vast network of logistics and delivery services. Optimizing delivery routes and ensuring agents can efficiently reach designated points is crucial for timely deliveries and operational efficiency. This problem simulates a scenario where a delivery agent needs to explore a given area, such as a warehouse or a city block, to identify the maximum number of unique delivery points they can access within a specified time limit, while navigating around obstacles.
Your task is to implement a function that calculates the maximum number of unique delivery points a Delhivery agent can reach starting from a given position within a maximum number of moves.
maxMoves from the startRow, startCol.Input:
grid: An m x n matrix (2D array) of characters representing the delivery area. Each cell can be:
'0': An open path, traversable.'1': An obstacle, non-traversable.'D': A delivery point, traversable and counts towards reachable delivery points.startRow: An integer representing the starting row index of the agent.startCol: An integer representing the starting column index of the agent.maxMoves: An integer representing the maximum number of moves the agent can make.Output:
maxMoves.maxMoves >= 0. However, they cannot move from an obstacle cell. Assume startRow, startCol will always be a valid, non-obstacle cell.maxMoves is 0, the agent can only "reach" the starting cell. If it's a 'D', count 1. Otherwise, 0.Examples
Example 1
Input:
grid = [["0","D","0"],["0","1","0"],["D","0","0"]], startRow = 0, startCol = 0, maxMoves = 2
Output:
2
Note:
From (0,0):
Example 2
Input:
grid = [["D","0","D"],["0","1","0"],["D","0","D"]], startRow = 0, startCol = 0, maxMoves = 0
Output:
1
Note:
The agent starts at (0,0) which is a 'D' point. With 0 moves, only the starting cell can be reached, thus counting 1 unique delivery point.
Example 3
Input:
grid = [["0","0","0"],["0","1","0"],["0","0","0"]], startRow = 0, startCol = 0, maxMoves = 1
Output:
0
Note:
From (0,0), the agent can move to (0,1) or (1,0). Neither of these cells are 'D' points. No 'D' points reachable within 1 move.
Constraints
1 <= m, n <= 100 (grid dimensions)grid[i][j] will be one of '0', '1', 'D'.0 <= startRow < m0 <= startCol < ngrid[startRow][startCol] will not be '1'.0 <= maxMoves <= m * nmaxMoves constraint.Loading editor...