Skip to content

Instantly share code, notes, and snippets.

@vmamore
Last active September 22, 2020 15:26
Show Gist options
  • Select an option

  • Save vmamore/2ff1f2f31f787244a8143c73ded30495 to your computer and use it in GitHub Desktop.

Select an option

Save vmamore/2ff1f2f31f787244a8143c73ded30495 to your computer and use it in GitHub Desktop.

Revisions

  1. vmamore revised this gist Sep 22, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions SockMerchant.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // 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
    // Complete the sockMerchant function below.
    static int sockMerchant(int n, int[] ar) {
    var hashSet = new HashSet<int>();
    int pairs = 0;
  2. vmamore revised this gist Sep 22, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions SockMerchant.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // 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
    // Complete the sockMerchant function below.
    static int sockMerchant(int n, int[] ar) {
    var hashSet = new HashSet<int>();
  3. vmamore renamed this gist Sep 22, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. vmamore created this gist Sep 22, 2020.
    15 changes: 15 additions & 0 deletions .cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // Complete the sockMerchant function below.
    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;
    }