Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_pair_with_sum(a, need):
- s= set()
- for i in a:
- if (need- i) in s:
- print(need-i, i)
- else:
- s.add(i)
- a=[4,2,4,2]
- b=[3,6,2,5]
- need= 8
- # find subset with sum = 8
- get_pair_with_sum(a, need) #prints [4,4]
- print()
- get_pair_with_sum(b, need) #prints [6,2], [3,5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement