Engineering Full Stack Apps with Java and JavaScript
Here we will see the approaches for the problems given @ http://javajee.com/problems-summary-of-problems-on-linked-lists-for-inte....
Reverse a linked list
Remove duplicates from a sorted linked list.
Remove duplicates from an unsorted linked list.
Find the Kth to last element in a linked list
Delete a node in the middle of a singly linked list, given only access to that node.
Given a linked list with a loop (circular linked list), find the node at the beginning of the loop.
Partitian a linked list around a given value x, with all nodes with values less than x should come before all nodes with values greater than or equal to x.
Given two sorted (ascending) linked lists L1 and L2. Write a program to merge them into a single descending linked list.
Example:
List1 = 5>15>25>35>null.
List2 = 1>10>20>30>null.
ResultList = 35>30>25>20>15>10>5>1>null.
Find the middle element of linked list in one Pass?
Approach: You can use the runner technique. Two pointers can be used and both will be running at separate speeds. One runner pointer can go in two steps at a time and other pointer can go in one step at a time. Second one will always cover half the distance as that of the other. When one reaches the end, other will be be middle.