Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save algotrader-dotcom/46fab0805b8a325a7dc612561f8559f9 to your computer and use it in GitHub Desktop.

Select an option

Save algotrader-dotcom/46fab0805b8a325a7dc612561f8559f9 to your computer and use it in GitHub Desktop.
hackerrank - Sock Merchant - python3
#!/bin/python3
import sys
n = 10
arr = [1, 1, 3, 1, 2, 1, 3, 3, 3, 3 ]
arr_m = {}
def calculatePairs(a,arr):
match_count = 0
for item in arr:
if item == a:
match_count = match_count + 1
if match_count%2 == 0:
match_count = match_count/2
else:
match_count = match_count - 1
match_count = match_count/2
return match_count
def main():
n = input()
arr = input().split(" ")
#print(arr)
#return
for a in arr:
mc = calculatePairs(a,arr)
arr_m[a] = mc
result = 0
for key in arr_m:
#print(arr_m[key])
result = result + int(arr_m[key])
print(result)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment