Created
October 1, 2014 18:10
-
-
Save 17twenty/74d64c6593a50ec64f59 to your computer and use it in GitHub Desktop.
Amazon coding test
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/env python | |
import sys | |
N,K = (int(val) for val in sys.stdin.readline().split()) | |
setN = [int(val) for val in sys.stdin.read().split()] | |
# Should we check len(setN) <= N? | |
# We should sort such that we can optimise | |
setN.sort() | |
# Ok, so bruteforce is O(n) - try set intersection for cardinality? | |
matchSet = [i + K for i in setN] | |
print len(set(setN).intersection(set(matchSet))) | |
print setN | |
print matchSet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't remember where I read about this challenge but yeah - this would be what I'd expect from it.