def two_sum(arr, target):
arr.sort()
left, right = 0, len(arr) - 1
while left < right:
if arr[left] + arr[right] == target:
# we reach find the answer
return True
elif arr[left] + arr[right] < target:
# this means arr[left] can't pair
# the elements before arr[right],
# safely igonre the element arr[left]
left += 1
elif arr[left] + arr[right] > target:
# this means arr[right] can't pair
# the elements after arr[left],
# safely igonre the element arr[right]
right -= 1
return False
# Driver Code
arr = [2, 5, 8, 11, 12, 30]
result = two_sum(arr, 23)
print(result)