using System.Collections.Generic;
public static Node DuplicateRemoval(Node n)
if (n == null || n.Next == null)
HashSet<int> numSet = new HashSet<int>();
while (second.Next != null)
if (numSet.Contains(second.Data))
if (numSet.Contains(second.Data))
public static Node KthToLast(int k, Node n)
for (int i = 0; i < k; i++)
public static void DeleteMiddleNode(Node n)
while (n.Next.Next != null)
public static void PrintLinkedList(Node n)
Console.Write(n.Data + " -> ");
Console.WriteLine(n.Data);
public static Node CreateLinkedList(List<int> lst)
Node n = new Node(lst[0]);
for (int i = 1; i < lst.Count; i++)
n.Next = new Node(lst[i]);
public static void Main()
Node linkedList = new Node(4);
linkedList.Next = new Node(3);
linkedList.Next.Next = new Node(5);
DeleteMiddleNode(linkedList.Next);
PrintLinkedList(linkedList);
Console.WriteLine("Hello World");