Delete a Node HackerRank Solution


Delete a Node HackerRank Solution
Source : https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list



Source : https://www.hackerrank.com/challenges/delete-a-node-from-a-linked-list


Solution


// Karthikalapati.blogspot.com
/*
Delete Node at a given position in a linked list
Node is defined as
class Node {
int data;
Node next;
}
*/
Node Delete(Node head, int position) {
if (head == null) {
return null;
} else if (position == 0) {
return head.next;
} else {
/* Get Node one element before desired position */
Node n = head;
for (int i = 0; i < position - 1; i++) {
n = n.next;
}
/* Delete Node */
n.next = n.next.next;
return head;
}
}

6 comments:

  1. You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. packers and movers salem

    ReplyDelete
  2. Aw, this became a very good post. In concept I must set up writing like this moreover – taking time and actual effort to produce a really good article… but exactly what can I say… I procrastinate alot and by no indicates apparently go completed. electronic accessories shop near me

    ReplyDelete
  3. I don’t know if it’s just me or if perhaps everyone else encountering problems with your blog. It seems like some of the written text within your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a problem with my internet browser because I’ve had this happen previously. Many thanks 하이브슬롯

    ReplyDelete
  4. Listcry is leading Car Transportation for House Shifting, Goods Transport, Cargo & Commercial Shifting Provider at best Charges . Packers and Movers Noida to Bangalore

    ReplyDelete
  5. Thanks for this post, I am a big fan of this web site would like to proceed updated. 꽁머니커뮤니티

    ReplyDelete