Trains the technique from
LeetCode 3201Find the Maximum Length of Valid Subsequence IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A conveyor carries parcels past you, loads[i] being the weight of the i-th.
Pick out some of the parcels, keeping the order they came in. Add up each neighbouring pair of the parcels you picked: the first with the second, the second with the third, and so on. Your pick counts as steady when those totals are all even or all odd.
Return the largest number of parcels a steady pick can hold. A pick of one or two parcels is always steady, since there is no second total to disagree with the first.
Example 1
The weights already run odd, even, odd, even down the conveyor, so every neighbouring total is odd and the whole run is steady on its own.
Example 2
Dropping the second parcel of weight 3 leaves weights 1, 2, 3 and 4, whose totals 3, 5 and 7 are all odd. Keeping all five would stand the two 3s side by side for an even total.
Example 3
Taking the six parcels of weight 6 makes every neighbouring total 12, all even. Alternating instead would have to stop at five parcels, since only two odd weights are on offer.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_length(loads: list[int]) -> int:public int maximumLength(int[] loads)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.