Daily challenge for 2026-09-09
617. Two-End Toll Booths
Drivers enter a tollway from either the left or right end. You are given a list of vehicle weights weights and a positive integer limit representing the maximum allowable combined weight of two entering vehicles.
Two inspectors work inwards simultaneously: one vehicle is processed from the left and one from the right. If the pair's combined weight weights[left] + weights[right] does not exceed limit, both vehicles pass through as a verified pair. Otherwise, the inspectors cannot pair them and stop.
The process continues inwards step-by-step until the two inspectors meet or cross, or until a pair exceeds the limit.
Return the total number of verified pairs processed.
Example:Input: weights = [2, 3, 5, 4], limit = 7Output: 1
Explanation: First pair is from left (2) and right (4), sum is 6 <= 7. Second pair is from next left (3) and next right (5), sum is 8 > 7, so inspectors stop. Total verified pairs = 1.