Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created October 1, 2014 18:10
Show Gist options
  • Save 17twenty/74d64c6593a50ec64f59 to your computer and use it in GitHub Desktop.
Save 17twenty/74d64c6593a50ec64f59 to your computer and use it in GitHub Desktop.
Amazon coding test
#!/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
@17twenty
Copy link
Author

17twenty commented Oct 1, 2014

I can't remember where I read about this challenge but yeah - this would be what I'd expect from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment