Given a list of package weights and a target combined weight, determine if any two distinct packages can be paired to match the target. Output 'YES' or 'NO'.
Explanation: Step-by-step: with input [7, 18, 4, 5, 10, 12, 15, 20, 25, 30], we sort the array in ascending order. Then, we iterate through the array and check for each element if its complement (target combined weight - current element) exists in the array. If it does, we return 'YES'. If we reach the end of the array without finding a pair, we return 'NO'.
Explanation: Step-by-step: with input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], we sort the array in ascending order. Then, we iterate through the array and check for each element if its complement (target combined weight - current element) exists in the array. If it does, we return 'YES'. If we reach the end of the array without finding a pair, we return 'NO'.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak