BackeasyHashing Capgemini

Pair Sum Match Solution

Problem Statement

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'.

Example 1
Input
[7, 18, 4, 5, 10, 12, 15, 20, 25, 30]
Output
YES

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'.

Example 2
Input
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output
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'.

Constraints

  • 2 <= n <= 10^5
  • 1 <= arr[i] <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free