Last active
April 7, 2021 23:50
-
-
Save stephensanwo/f986f37b9f1949640760055e82ed7e3e to your computer and use it in GitHub Desktop.
Algorithms and Data Structures
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
# find the pairs of numbers in list ar of length n, and return the number of pairs in the list | |
n = 9 | |
ar = [10, 20, 20, 10, 10, 30, 50, 10, 20] | |
def sockMerchant(n, ar): | |
i = 0 | |
data = sorted(ar) | |
pair = 0 | |
while i < len(data)-1: | |
if data[i] == data[i+1]: | |
i += 2 | |
pair += 1 | |
else: | |
i += 1 | |
if i == len(data): | |
break | |
return pair |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment