Skip to main content
6/25

Find Pair With Target Sum

Easy

You are given a list of numbers and a target sum.


Find two different numbers from the list whose sum is equal to the target value.


Return the two matching numbers.


If no valid pair exists, return an empty list {}.


A number cannot be matched with itself unless the same value appears more than once at different positions in the list.


Rule Inputs

ri!numbers - List of Integer
ri!targetSum - Integer


ri! Rule Inputs

ri!numbersList of Number (Integer)
{
  50,
  120,
  75,
  200,
  30
}
ri!targetSumNumber (Integer)
195

Example 1: Case 1

Input: ri!numbers
{
  50,
  120,
  75,
  200,
  30
}
Input: ri!targetSum
195
Output:
{
  120,
  75
}

Example 2: Case 2

Input: ri!numbers
{
  20,
  50,
  50,
  90
}
Input: ri!targetSum
100
Output:
{
  50,
  50
}

Example 3: Case 3

Input: ri!numbers
{
  10,
  20,
  30,
  40
}
Input: ri!targetSum
100
Output:
{}

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter