{"id":5753,"date":"2026-02-10T15:19:04","date_gmt":"2026-02-10T15:19:04","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5753"},"modified":"2026-02-10T15:20:48","modified_gmt":"2026-02-10T15:20:48","slug":"remove-nth-node-from-linked-list","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/remove-nth-node-from-linked-list\/","title":{"rendered":"Remove Nth Node from Linked List"},"content":{"rendered":"<p><strong class=\"ctaHeader3\">Remove Nth Node from Linked List<\/strong><\/p>\n<p>Remove 3rd node from below list<br \/>\n<strong>Input<\/strong><\/p>\n<pre>\r\nAnbu -> Arul -> Arasu-> Bharath-> Catherine -> Davidson\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\nAnbu -> Arul -> Bharath-> Catherine -> Davidson\r\n<\/pre>\n<p><strong>Idea:<\/strong> Traverse to the Kth Position and point the reference of temp to one next to it. We need to handle one edge case which is when the Kth position is first node then in such case the head should be changed to point temp next position.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class RemoveNthNodeFromLL {\r\n    public static void main(String&#x5B;] args) {\r\n        SimpleLinkedList simpleLinkedList = new SimpleLinkedList();\r\n\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Anbu&quot;);\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Arul&quot;);\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Arasu&quot;);\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Bharath&quot;);\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Catherine&quot;);\r\n        simpleLinkedList.insertNodeAtEnd(&quot;Davidson&quot;);\r\n\r\n        simpleLinkedList.printLinkedList();\r\n\r\n        System.out.println(&quot;--------------After Removing 3rd Node--------------&quot;);\r\n\r\n        removeNthNode(simpleLinkedList, 3);\r\n\r\n        simpleLinkedList.printLinkedList();\r\n    }\r\n\r\n\r\n     public static void removeNthNode(SimpleLinkedList simpleLinkedList, Integer indexOfNodeToBeRemoved){\r\n        Node temp = simpleLinkedList.head;\r\n\r\n        \/\/Edgecase1 : If Kth index is 1\r\n        if(indexOfNodeToBeRemoved == 1){\r\n            simpleLinkedList.head = temp.next;\r\n            return;\r\n        }\r\n\r\n        for(int idx=1;idx&lt;indexOfNodeToBeRemoved-1;idx++){\r\n            temp = temp.next;\r\n        }\r\n\r\n        temp.next = temp.next.next;\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\nAnbu\r\nArul\r\nArasu\r\nBharath\r\nCatherine\r\nDavidson\r\n--------------After Removing 3rd Node--------------\r\nAnbu\r\nArul\r\nBharath\r\nCatherine\r\nDavidson\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Remove Nth Node from Linked List Remove 3rd node from below list Input Anbu -> Arul -> Arasu-> Bharath-> Catherine -> Davidson Output Anbu -> Arul -> Bharath-> Catherine -> Davidson Idea: Traverse to the Kth Position and point the reference of temp to one next to it. We need to handle one edge case&hellip; <a href=\"https:\/\/codethataint.com\/blog\/remove-nth-node-from-linked-list\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[229],"tags":[],"class_list":["post-5753","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5753"}],"version-history":[{"count":3,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5753\/revisions"}],"predecessor-version":[{"id":5756,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5753\/revisions\/5756"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}