Last active
September 22, 2020 15:26
-
-
Save vmamore/2ff1f2f31f787244a8143c73ded30495 to your computer and use it in GitHub Desktop.
[HR] - Sales by Match | https://www.hackerrank.com/challenges/sock-merchant/problem?h_l=interview&playlist_slugs%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D=warmup
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
| static int sockMerchant(int n, int[] ar) { | |
| var hashSet = new HashSet<int>(); | |
| int pairs = 0; | |
| for(int i = 0; i < n; i ++){ | |
| if(!hashSet.Contains(ar[i])) { | |
| hashSet.Add(ar[i]); | |
| } else { | |
| pairs++; | |
| hashSet.Remove(ar[i]); | |
| } | |
| } | |
| return pairs; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment