Forked from ariestiyansyah/Codility Complementary Pairs (Contenga)
Last active
August 29, 2015 14:10
-
-
Save venkatesh22/8478477d9bf3d0feffa9 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
A = [1, 8, -3, 0, 1, 3, -2, 4, 5] | |
def solution(K, A): | |
contenga = {} | |
for x in A: | |
if x not in contenga: | |
contenga[x] = 0 | |
contenga[x] += 1 | |
N = 0 | |
for i in contenga: | |
N += contenga[i] * contenga.get(K-i, 0) | |
return N | |
print solution(6, A) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment