Created
January 3, 2020 12:17
-
-
Save kranthi0987/8f6742f80a3e8c71f6028b80b56c02b1 to your computer and use it in GitHub Desktop.
Hackerrank Sock-market solution
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
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# Complete the sockMerchant function below. | |
def sockMerchant(n, ar): | |
count = 0 | |
ar.sort() | |
ar.append('#') | |
i = 0 | |
while i<n: | |
if ar[i]==ar[i+1]: | |
count = count+1 | |
i+=2 | |
else: | |
i+=1 | |
return count | |
if __name__ == '__main__': | |
fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
n = int(input()) | |
ar = list(map(int, input().rstrip().split())) | |
result = sockMerchant(n, ar) | |
fptr.write(str(result) + '\n') | |
fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment