Skip to content

Instantly share code, notes, and snippets.

@gauravbansal74
Created June 30, 2019 08:55
Show Gist options
  • Save gauravbansal74/5f1bc40857589a522451f8fc9db71ca4 to your computer and use it in GitHub Desktop.
Save gauravbansal74/5f1bc40857589a522451f8fc9db71ca4 to your computer and use it in GitHub Desktop.
Sock Merchant || HackerRank
static int sockMerchant(int n, int[] arr) {
Set<Integer> colors = new HashSet<>();
int pairs = 0;
if(n == arr.length){
for (int i = 0; i < n; i++) {
if (colors.remove(arr[i])) {
pairs++;
} else {
colors.add(arr[i]);
}
}
}
return pairs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment