I am solving linked list question on geeksforgeeks platform and i was given a question, i will mention the link to check it. I am getting nullpointer expection for this. link:- https://practice.geeksforgeeks.org/problems/linked-list-insertion-1587115620/1/?category[]=Linked%20List&difficulty[]=-1&page=1&query=category[]Linked%20Listdifficulty[]-1page1#
Code:-
 Node insertAtBeginning(Node head, int x)
{
    // code here
    Node inserting = new Node(x);
    inserting.next = head;
    return inserting;
}
// Should insert a node at the end
Node insertAtEnd(Node head, int x)
{
    // code here
    Node first = head;
    while(head.next != null){
        head = head.next;
    }
    Node inserting = new Node(x);
    head.next = inserting;
    return first;
    
}
 
    