Skip to content

Practice Delivering Boxes from Storage to Ports

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1687
LeetCode Problem

Delivering Boxes from Storage to Ports

Problem Statement

Deliver boxes in their input order using one ship; boxes[i] = [port,weight]. Each loading takes a consecutive batch within both maxBoxes and maxWeight. Travel from storage to the first required port, then to each different next port while unloading in order; consecutive boxes for the current port require no additional trip. Return to storage after every batch, including the last. Return the minimum total number of trips.

Source: Delivering Boxes from Storage to Ports on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3
Output
4

# Example 2

Input
boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6
Output
6

# Example 3

Input
boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7
Output
6

Constraints

1 <= boxes.length <= 10^5
1 <= portsCount, maxBoxes, maxWeight <= 10^5
1 <= ports​​i <= portsCount
1 <= weightsi <= maxWeight

Related LeetCode Problems

Practice more problems similar to Delivering Boxes from Storage to Ports.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.