Created
November 9, 2018 10:12
-
-
Save algotrader-dotcom/46fab0805b8a325a7dc612561f8559f9 to your computer and use it in GitHub Desktop.
hackerrank - Sock Merchant - python3
This file contains hidden or 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
| #!/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