Problem Set #6: Lovely Linked Lists

Linked Lists are one of my favorite data structures. It is also staple material for computer science interviews. Throughout your CS career, you will probably run into Linked Lists or related data structures several times. Here are some practice problems to get you comfortable with Linked Lists:

1. public Node getNthFromEnd(int i):  
Write a method that will return the n-th node from the end of the linked list.

2. public List copy():  
Write a method that will copy and return the contents of a linked list.

3. public List cumulativeSum():  
Write a method to return a new linked list where each node 'n' contains the cumulative sum of numbers stored in the first node to that node 'n'. For example, {1, 2, 3, 4} should become {1, 3, 6, 10}.

4. public List merge(List l1, List l2):  
Write a method to return return a new list containing all the nodes in both 'l1' and 'l2'