Amazon Interview Question

Given a singly linked list, find the kth element from the back and delete it.

Interview Answers

Anonymous

Feb 18, 2015

Hey was there only one question?

Anonymous

Jan 23, 2017

somewhat pseudo code. Node slow = head, fast = head; slowback = head; //give distance between two iterators for(int i = 0; i < k; i++){ fast = fast.next; } //reaches the last kth element while(fast != null){ fast = fast.next; slowback = slow; slow = slow.next; } //delete the kth node from last, and change next pointer of the node before it to the next next node slowback.next = slow.next; slow = null;