Trains the technique from
LeetCode 1679Max Number of K-Sum PairsThis 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 loading bay has crates on the floor; weights[i] is the weight of crate i in kilograms. A pallet is only accepted when it carries exactly target kilograms in exactly two crates.
One loading step chooses two crates still on the floor whose weights add up to target and moves both of them onto a pallet, out of reach of later steps. Return the largest number of loading steps that can be carried out.
Example 1
Load 1 with 9, then 3 with 7, then the two crates of 5. Each pallet carries exactly 10 kilograms in two crates, and the floor is empty, so 3 steps are done.
Example 2
Two crates of 2 make one pallet of 4, and the other two make a second. Each crate is used on one pallet only, so 2 steps are done.
Example 3
The crate of 1 pairs with a crate of 3 for a pallet of 4. The two crates of 3 still on the floor add up to 6, not 4, so no further step is possible and the answer is 1.
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 max_operations(weights: list[int], target: int) -> int:public int maxOperations(int[] weights, int target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.