Skip to main content

Posts

Showing posts with the label interview preparation

HACKERRANK -- DELETE A NODE AT A GIVEN POSITION

  HACKERRANK --  DELETE A NODE AT A GIVEN POSITION Delete the node at a given position in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, return a null value. Example After removing the node at position  ,  . Function Description Complete the  deleteNode  function in the editor below. deleteNode  has the following parameters: -  SinglyLinkedListNode pointer llist:  a reference to the head node in the list -  int position:  the position of the node to remove Returns -  SinglyLinkedListNode pointer:  a reference to the head of the modified list Input Format The first line of input contains an integer  , the number of elements in the linked list. Each of the next   lines contains an integer, the node data values in order. The last line contains an integer,  , the position of the node to delete. Constraints , wh...

LINKED LIST -- INSERT A NODE AT A PARTICULAR POSITION

  LINKED LIST -- INSERT A NODE AT A PARTICULAR POSITION Given the pointer to the head node of a linked list and an integer to insert at a certain position, create a new node with the given integer as its   attribute, insert this node at the desired position and return the head node. A position of 0 indicates head, a position of 1 indicates one node away from the head and so on. The head pointer given may be null meaning that the initial list is empty. Example  refers to the first node in the list  Insert a node at position   with  . The new list is  Function Description  Complete the function  insertNodeAtPosition  in the editor below. It must return a reference to the head node of your finished list. insertNodeAtPosition has the following parameters: head : a SinglyLinkedListNode pointer to the head of the list data : an integer value to insert as data in your new node position : an integer position to insert the new node, zer...