/* Given a linked list consisting of N nodes and an integer K, your task is to delete the Kth node from the end of the linked list */ // Time Complexity: O(n). // Space complexity: O(1). import java.util.*; import java.io.*; class LinkedList { Node head; class Node { int data; Node next; Node(int d) { data = d; next = null; } } public void push(int new_data) { Node new_node = new Node(new_data); new_node.next = head; head = new_node; } void deleteNode(int position) { if (head == null) return; Node temp = head; if (position == 0) { head = temp.next; return; } for (int i=0; temp!=null && i0 ){ int n = sc.nextInt(); int k = sc.nextInt(); LinkedList llist = new LinkedList(); int p[]=new int[n]; for(int i=0;i=0;i--) { llist.push(p[i]); } llist.deleteNode(k-1); llist.printList(); } } } /* Given: 1->2->3->4->5->6 K=3 after deletion: 1->2->3->5->6 4 is the third last node from the end of linked list. */