What is the error in my code? It's failing for 2 test cases

import java.util.*;

class Node{
int data;
Node next;
Node(int data){
this.data = data;
}
}

class Main{
public static Scanner scn = new Scanner(System.in);

public static void removeCycle(Node head){
    Node slow = head;
    Node fast = head;

    while(slow!= null &&fast.next!=null && fast.next.next!=null){
        slow = slow.next;
        fast = fast.next.next;

        if(slow == fast){
            break;                          //cycle detected
        }
    }


    if(slow == fast){
        removeLoop(slow,head);
    }

}

public static void removeLoop(Node loop, Node head){
    Node ptr1 = loop;
    Node ptr2 = loop;
    //Step1 Count the no of nodes in loop(counter)
    int counter = 1;
    while(ptr1.next != ptr2){
        ptr1 = ptr1.next;
        counter++;
    }

    ptr1 = head;
    ptr2 = head;

    while(counter-->0){
        ptr2 = ptr2.next;       //move other pointer counter times ahead
    }

    while(ptr1 != ptr2){        //both of them will meet at starting point of loop
        ptr1 = ptr1.next;
        ptr2 = ptr2.next;
    }

    while(ptr2.next!=ptr1){         //finding the end node of loop to break
        ptr2 = ptr2.next;
    }

    ptr2.next = null;                   //breaking the loop
}

public static Node buildList(){
    HashMap <Integer, Node> map = new HashMap<>();
    int x = scn.nextInt();
    Node head = new Node(x);
    Node curr = head;
    while(x!=-1){
        x = scn.nextInt();
        if(x==-1){
            break;
        }

        if(map.containsKey(x)){
            Node temp = map.get(x);
            curr.next = temp;
            curr = temp;
        }else{
            Node nn = new Node(x);
            map.put(x,nn);
            curr.next = nn;
            curr = nn;
        }
    }

    return head;
} 

public static void display(Node head){
    Node curr = head;
    while(curr != null){
        System.out.print(curr.data+" ");
        curr = curr.next;
    }
    System.out.println();
}

public static void main(String []args){
    Node l1 = buildList();
    removeCycle(l1);

    display(l1);
}

}

@ap8730390,

Input:
1 2 3 1 2 3 1 2 3 1 2 3 -1
Expected Output:
1 2 3
Your Output:
1 2 3 1

I am still not able to identify the error in my code. I even dry ran my code and was unable to locate error. Please help

@ap8730390,
There was an error in the construction of LL. You did not add the head to the map, hence it was getting added again.
https://ide.codingblocks.com/s/254941 here is corrected code. I have mentioned the line I have added in the code.

Just need to add before entering the while loop.

map.put(x, head);