"""
Given an array of integers and a value, determine if there are any two integers in the array whose sum is equal to the given value.

Given an array of integers and a value, determine if there are any two integers in the array whose sum is equal to the given value. Return true if the sum exists and return false if it does not.
"""


# unsorted input
def find_sum_of_two(A, val):
    s = set()
    for n in A:
        if val - n in s:
            return True
        s.add(n)
    return False


# soerted


def find_sum_of_two(A, val):
    left = 0
    right = len(A) - 1

    while left < right:
        _s = A[left] + A[right]

        if _s == val:
            return True
        elif _s < val:
            left += 1
        else:
            right -= 1
    return False
