PracticeArrays
Validate Warehouse Dispatch Signals
Context
A regional warehouse records one integer dispatch signal for each shipment scheduled on a route. A nonzero signal means the shipment has a usable dispatch record, while zero means the record is missing. Before releasing the route, the logistics system must decide whether every recorded signal is usable.
Problem
Write a function that returns whether every dispatch signal in the given sequence is truthy. For this problem, an integer is truthy exactly when it is nonzero; both positive and negative nonzero values count as truthy, while zero is falsy. An empty sequence passes the universal check. Scan from left to right, and stop as soon as a falsy signal is found.
Examples
Example 1
Input:
signals = [4, -2, 7]Output:
TrueExplanation: The executed call with [4, -2, 7] returns true, and its final validity flag is true.
Example 2
Input:
signals = [5, 3, 0, 8]Output:
FalseExplanation: The executed call with [5, 3, 0, 8] returns false, and its final validity flag is false.
Example 3
Input:
signals = []Output:
TrueExplanation: The executed call with an empty sequence returns true, and its final validity flag is true.
Constraints
0 <= len(signals) <= 100-1000 <= signals[i] <= 1000 for every i- Types:
signalsis int[]; result is bool
Function signature
def all_dispatch_signals_valid(signals: list[int]) -> bool
signalslist[int]- Dispatch signals recorded for the route, one integer per shipment.
- returns bool
- Return true if every signal is nonzero, including when the sequence is empty; otherwise return false.
Adapted from MBPP problem task_713 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The required predicate is integer truthiness: zero is falsy and every nonzero integer is truthy.
- Repeated signals do not receive special treatment.
Code
Saved