input: Write a python function to detect and remove loop in a linked list.
  assert llist.detectAndRemoveLoop([1, 2, 3, 4, 2]) == [1, 2, 3, 4]
  assert llist.detectAndRemoveLoop([1, 3, 4, 5, 6, 3]) == [1, 3, 4, 5, 6]
  assert llist.detectAndRemoveLoop([10, 20, 30, 40, 20]) == [10, 20, 30, 40]
output: class Node:
      def __init__(self, data):
          self.data = data
          self.next = None
  
  class LinkedList:
      def __init__(self):
          self.head = None
  
      def detectAndRemoveLoop(self, arr):
          self.head = self.createLinkedList(arr)
          if self.detectLoop():
              self.removeLoop()
          return self.toList()
  
      def createLinkedList(self, arr):
          if not arr:
              return None
          head = Node(arr[0])
          current = head
          node_map = {head.data: head}
  
          for value in arr[1:]:
              if value in node_map:
                  current.next = node_map[value]
                  break
              new_node = Node(value)
              node_map[value] = new_node
              current.next = new_node
              current = new_node
  
          return head
  
      def detectLoop(self):
          slow = fast = self.head
          while fast and fast.next:
              slow = slow.next
              fast = fast.next.next
              if slow == fast:
                  self.loop_node = slow
                  return True
          return False
  
      def removeLoop(self):
          if self.loop_node == self.head:
              while self.loop_node.next != self.head:
                  self.loop_node = self.loop_node.next
              self.loop_node.next = None
          else:
              ptr1 = self.head
              ptr2 = self.loop_node
              while ptr1.next != ptr2.next:
                  ptr1 = ptr1.next
                  ptr2 = ptr2.next
              ptr2.next = None
  
      def toList(self):
          result = []
          current = self.head
          while current:
              result.append(current.data)
              current = current.next
          return result
  
  llist = LinkedList()