Skip to content

Instantly share code, notes, and snippets.

@santhalakshminarayana
Created August 31, 2019 14:28
Show Gist options
  • Save santhalakshminarayana/fc505fbdf76098318ebe287b40365564 to your computer and use it in GitHub Desktop.
Save santhalakshminarayana/fc505fbdf76098318ebe287b40365564 to your computer and use it in GitHub Desktop.
Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
def find_sum_eq_k(l ,k):
l = sorted(l)
start ,end = 0 ,len(l)-1
found = False
while(found != True and end >= 0 and start < len(l)):
if(l[start] + l[end] == k):
found=True
elif(l[start] + l[end] < k):
start += 1
else:
end -= 1
return found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment