## Interview Practice Extra 04 – Remove Node from Singly Linked List

Question How do you remove a node from a singly linked list, given only that node? Head node is not given. Solution Set next of this node to the next of the next node. node->next = node->next->next; Reference Glassdoor

## Interview Practice 24 – Reverse a Linked List

Question Reverse a linked list. Sample # node structure class Node: value = None next = None def __init__(self, value, next_node=None): self.value = value self.next = next_node # reverse the linked list and return the head node def reverse_linked_list(head): reversed_head = None last_node = None node = head while node: next_node = node.next if next_node…

## Interview Practice Extra 02 – Duplicates in List

Question Write an algorithm to remove duplicated node from a linked list. Solution There are many ways to do it. For the first one, as the simplest one, we could use 2 loops to compare each element with all other elements. However, this takes forever: O(n²). The second way Reference http://www.geeksforgeeks.org/remove-duplicates-from-an-unsorted-linked-list/

## Interview Practice Extra 01 – Find Loop in Linked List

Question Validate a linked list whether there is a loop in it. That is, there is a node in a linked list with  the next pointer pointing to a node ahead in the same linked list. This is the question I encountered in 2013 spring, from a Yahoo phone interview. Solution Define 2 pointers pointing to…

## Interview Practice 13 – Last Kth Node of Linked List

Question Given a linked list, find the Kth last node in a linked list. The last 0th node is the tail node in the linked list. Solution Easy task. Construct 2 pointers: P1 and P2. First, both of them are set to head. Move P2 to the next Kth node. Example # node structure class…

## Interview Practice 11 – Greatest Distance Between Two Nodes in Binary Tree

Get the greatest distance between two nodes in a binary tree. Assume links between nodes are bidirectional. Distance is defined as the amount of nodes connected along the path linked two nodes.

## Interview Practice 07 – Determine if Two Linked Lists Intersect

Question Given 2 linked list head pointers, determine whether they intersect at some point. Solution First of all, linked list can have loop or not, and this gives 3 possible situations. 1. For the 2 loops head pointer 1 and head pointer 2, move pointer 1 at normal speed, and pointer 2 at double speed….

## Interview Practice 01 – Convert Binary Tree into Doubly Linked List

Question Convert binary search tree into doubly linked list. It’s required not to create any new node, but only turning pointers. Solution The following shows the concept of this question. 8 / 6 0 -> 5 = 6 = 7 = 8 = 9 = 0 = 1 / / 5 7 9 1 First,…