Last active
May 11, 2019 18:03
-
-
Save syntacticsugar/719dc805fda6a71c6a34f2524aeb14f1 to your computer and use it in GitHub Desktop.
For an array of socks, return the total number of matching pairs. (integer represents a unique color)
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
n = 7 | |
arr = [ 1,2,1,2,1,3,2 ] | |
def matchingPairs(qty,socks): | |
pairs = 0 | |
counts = {} | |
for s in socks: | |
if s in counts: | |
counts[s] += 1 | |
else: | |
counts[s] = 1 | |
print(counts) | |
total = 0 | |
for val in counts.values(): | |
total = total + int(val/2) | |
return total | |
print (matchingPairs(n,arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment