Created
August 31, 2019 14:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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