FastPrepDrone Delivery with Battery Swap Stations
Problems/Drone Delivery with Battery Swap Stations

Drone Delivery with Battery Swap Stations

Cisco logoCisco● HardFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says: "Find the minimum number of moves required to fly from the depot at (sr, sc) to the customer at (er, ec), given a battery capacity B, a list of M swap-kiosk cells, and a fixed budget of K swap vouchers for the trip. Report -1 if no feasible delivery exists." It also says passing over a kiosk lets the drone swap in a charged battery only if it has an unused voucher.

The report gives no examples or limits and does not say which way the drone can move. Here, the drone moves up, down, left, or right, and a swap is optional and refills the battery to full. You get the grid, points, and kiosks as arrays instead of the text input format in the report.

The judged task matches the report at about 95%.

An autonomous delivery drone flies over a city grid. grid[r][c] is 0 for open airspace and 1 for a no-fly building. The drone starts at the depot start = [sr, sc] and must reach the customer at end = [er, ec]. Each move takes the drone one cell up, down, left, or right to an open cell inside the grid.

The battery lasts battery moves, and the drone starts fully charged. Every move uses one unit of charge, so the drone cannot move when its charge is 0.

stations lists the cells that have a battery-swap kiosk. While the drone is on a kiosk cell, it may swap in a fully charged battery, which sets its charge back to battery. Each swap uses one swap voucher, and the whole trip has only vouchers vouchers. Swapping is optional: the drone may fly over a kiosk without swapping, and it may swap at the same kiosk again on a later visit if it still has a voucher.

Return the minimum number of moves needed to fly from start to end. If no delivery is possible, return -1.

Function

minDeliveryMoves(grid: int[][], start: int[], end: int[], battery: int, stations: int[][], vouchers: int) → int

Examples

Example 1

grid = [[0,0,0,0],[1,1,0,1],[0,0,0,0]]start = [0,0]end = [2,0]battery = 4stations = [[1,2]]vouchers = 1return = 6

The only route is right along the top row to [0,2], down through [1,2], and left along the bottom row to [2,0]. It takes 6 moves, more than one battery.

After 3 moves the drone reaches the kiosk at [1,2] with 1 charge left. It uses its voucher there to swap, so it has 4 charge for the last 3 moves. The answer is 6.

Example 2

grid = [[0,0,0,0],[1,1,0,1],[0,0,0,0]]start = [0,0]end = [2,0]battery = 4stations = [[1,2]]vouchers = 0return = -1

This is the same city, but the trip has no vouchers. The only route needs 6 moves and one battery lasts 4, so the delivery is impossible and the answer is -1.

Example 3

grid = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]start = [0,0]end = [0,4]battery = 3stations = [[1,2],[2,4]]vouchers = 1return = 6

The direct route along the top row takes 4 moves, but one battery lasts only 3.

The kiosk at [1,2] is 3 moves from the depot and 3 moves from the customer, so flying there, swapping, and flying on takes 6 moves. The kiosk at [2,4] is 6 moves from the depot, which one battery cannot reach. The answer is 6.

Constraints

  • 1 <= grid.length, grid[i].length <= 50
  • All rows of grid have the same length, and every grid[i][j] is 0 or 1.
  • start and end are open cells of grid.
  • 1 <= battery <= 2500
  • 0 <= stations.length <= 50
  • Each stations[k] is a distinct open cell [row, col] of grid.
  • 0 <= vouchers <= 50

More Cisco problems

  • K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
  • Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
  • Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
All Cisco interview questionsSee Cisco hiring insights
Saved
public int minDeliveryMoves(int[][] grid, int[] start, int[] end, int battery, int[][] stations, int vouchers) {
    // Write your solution here.
}
Checking account…