title: delete nodes with values that are repeated more than 2 times
body: <p>I have a method that I want to delete nodes with values that are repeated more than 2 times, unfortunately it delete nodes that are appearing more than once. the input am inputting is</p>
  <blockquote>
  <p>E B E E B A B</p>
  </blockquote>
  <p>but I end up getting</p>
  <blockquote>
  <p>E B A</p>
  </blockquote>
  <p>Instead of getting</p>
  <blockquote>
  <p>E B E B A</p>
  </blockquote>
  <p>What am I doing wrong, have been scratching my head for hours,and I am not seeeing the issue, any guidance towards the right direction is accepted. Thank you in advance?</p>
  <p>this is my code</p>
  <pre><code>using System;
  using System.Collections.Generic;
  
  class removeDuplicates
  {
      class node
      {
          public String val;
          public node next;
  
          public node(String val) { this.val = val; }
      }
  
      static void removeDuplicate(node head)
      {
  
          HashSet&lt;String&gt; hs = new HashSet&lt;String&gt;();
  
          node current = head;
          node prev = null;
          while (current != null)
          {
              String curval = current.val;
  
          
              if (hs.Contains(curval))
              {
                  prev.next = current.next;
              }
              else
              {
                  hs.Add(curval);
                  prev = current;
              }
              current = current.next;
          }
      }
      
      static void printList(node head)
      {
          while (head != null)
          {
              Console.Write(head.val + &quot; &quot;);
              head = head.next;
          }
      }
  
      // Driver code
      public static void Main(String[] args)
      {
  
          // The constructed linked list is:
          // E-&gt;B-&gt;E-&gt;E-&gt;B-&gt;A-&gt;B
          node start = new node(&quot;E&quot;);
          start.next = new node(&quot;B&quot;);
          start.next.next = new node(&quot;E&quot;);
          start.next.next.next = new node(&quot;E&quot;);
          start.next.next.next.next = new node(&quot;B&quot;);
          start.next.next.next.next.next = new node(&quot;A&quot;);
          start.next.next.next.next.next.next = new node(&quot;B&quot;);
  
          Console.WriteLine(&quot;Linked list before removing &quot;
                          + &quot;duplicates :&quot;);
          printList(start);
  
          removeDuplicate(start);
  
          Console.WriteLine(&quot;\nLinked list after removing &quot;
                          + &quot;duplicates :&quot;);
          printList(start);
      }
  }
  </code></pre>