Baseline Binary Search · 1D Arrays O(n) · O(log n) recursion stack for the reference divide-and-conquer implementation
Conveyor stations along a production line each append an event with a sequence number to a shared audit trail. Before the report is signed off, an auditor must confirm every recorded number is greater than or equal to the previous one. Verify the ordering and flag the trail as valid or not.
Input: An integer n and an array arr of n integers.
Output: true when arr is sorted in non-decreasing order, otherwise false (the canonical judge prints 1 and 0).
1 <= n <= 10^5-10^9 <= arr[i] <= 10^9Equal neighbours are allowedInput: {"n":5,"arr":[10,20,30,40,50]}
Output: true
Every recorded number is greater than the one before it, so the trail is valid.
Input: {"n":5,"arr":[10,20,20,40,50]}
Output: true
The repeated 20 is acceptable because the rule is non-decreasing, not strictly increasing.