PracticeArrays

Validate Warehouse Dispatch Signals

BeginnerArraystraversalstate trackinginvariants Time not estimated Not started

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: True
Explanation: 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: False
Explanation: The executed call with [5, 3, 0, 8] returns false, and its final validity flag is false.
Example 3
Input: signals = []
Output: True
Explanation: 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: signals is int[]; result is bool

Function signature

def all_dispatch_signals_valid(signals: list[int]) -> bool
signals list[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.
Approved · c013-abs_113_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1