PracticeArrays

Consecutive Shipment Handoffs

BeginnerArraystraversalaccumulationstate tracking Time not estimated Not started

Context

A warehouse records shipment identifiers as parcels move through a loading line. For auditing, each shipment must be paired with the shipment immediately after it in the recorded order. Create the ordered list of all such neighboring handoffs.

Problem

Write a function that receives the shipment identifiers in their recorded order and returns every pair of consecutive identifiers. Each returned two-item array contains the value at one position followed by the value at the next position. Preserve the original order and keep repeated identifiers as separate positional pairs. If the record has fewer than two identifiers, return an empty collection.

Examples

Example 1
Input: shipments = [101, 205, 309, 412]
Output: [[101, 205], [205, 309], [309, 412]]
Explanation: For [101, 205, 309, 412], the executed output contains the consecutive pairs [[101, 205], [205, 309], [309, 412]].
Example 2
Input: shipments = [7, 7, 12, 7]
Output: [[7, 7], [7, 12], [12, 7]]
Explanation: For [7, 7, 12, 7], the executed output keeps the repeated 7 values as the positional pair [7, 7] and returns [[7, 7], [7, 12], [12, 7]].
Example 3
Input: shipments = []
Output: []
Explanation: For an empty shipment list, the executed output is an empty list.

Constraints

  • 0 <= len(shipments) <= 1000
  • -1000000 <= shipments[i] <= 1000000 for every i
  • Types: shipments is int[]; result is int[][]

Function signature

def list_shipment_handoffs(shipments: list[int]) -> list[list[int]]
shipments list[int]
Shipment identifiers in loading-line order.
returns list[list[int]]
An ordered collection of two-item arrays, one for each adjacent pair in shipments.

Adapted from MBPP problem task_766 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Notes

  • The output must contain only pairs formed from neighboring input positions.
  • Repeated values remain distinct when they occur at different positions.
Approved · cc019-abs_166_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1