Drone Delivery

Drone delevery service is goint to be tested in a location.

-The location has constructed homes on multiple identical grids throughout the town.

-Each grid has 50 homes and each grid is assigned a unique number.

-Each home within a grid has a unique number from 1 to 50.

So each home can be uniquely identified by its grid number and home number pair.

The simple algorithm for the initial rollout of the drone delivery service:

-A swarm of delivery drones will be deployed for the delivery.

-In each swarm there will be one drone for each unique housing grid that will receive deliveries.

-Each drone will start at home number 1 in the grid and advance until all delivery for the grid is complete.

-over the period of 1 minute each drone can move to the next house, can make a delivery or can stay at its current position.

-All products must be delivered in exact order in which the order was made.

Your task is to determine how long it will take a swarm of drones to complete a specified delivery.

For example,

1234-1, 1235-1, 1235-3, 1234-2

from the above sequence there are two housing grids, 1234 and 1235, and two homes to deliver to on each grid.

The swarm will perform the following tasks in order to deliver the products:

Time Drone - 1234 Drone - 1235
1 Deliver Product Wait at home 1
2 Move to Home 2 Deliver Product
3 Wait at Home 2 Move to Home 2
4 Wait at Home 2 Move to Home 3
5 Wait at Home 2 Deliver Product
6 Deliver Product Wait at Home 3

It will take 6 minutes to complete this delivery task.

There can be at most two drones. For each test case you will be given the total number of packages and sequence of locations.

def time_to_deliver(num_package, delivery_sequence):
    record = {}; schedule = []; T = 0

    for input in delivery_sequence:
        a  = input.split("-")
        schedule.append(a)
        drone = a[0]
        if drone not in record.keys():
            record[drone] = [0, 1]
    # update time
    for s in schedule:
        drone = s[0]
        dest = int(s[1])
        # get Time , Location tuple
        travelTime = dest - record[drone][1]
        diff= max(T - record[drone][0], abs(travelTime)) + 1
        record[drone][0] += diff
        # update curloc
        record[drone][1] = dest
        T = record[drone][0]
    return T

results matching ""

    No results matching ""