-1

Linked List Session 1

 First Session on Linked Lists


In this session, we will tackle two Linked List problems ranging in difficulty. We will be alternating between the array session and linked list, a solid understanding of both will aid understanding of data structures.


When solving the problems think about what the time & space complexity of your solution is, The approach to solving most problems is first to use the brute force approach to get the solution then think about how you'd optimize your solution.


First Problem: Reverse a Linked List?

you are given the head of a singly linked list and you are to reverse the list in place. 

Do not create a brand new list!

Assumptions you can make are that the head will not be: none/null.

function ReversedLinkedList(headLinkedList){

​}

//head is 2
input: 2->3->-4->5->6

//head is 6
output: 6->5->4->3->2


Second Problem: Merge Linked List?

Given two singly linked lists that are sorted, merge the two lists in place.

Do not create a brand new list!

The new merged list should maintain a sorted list

Assumptions you can make are that the head will not be: none/null.


function mergedLinkedList(LinkedListOne,LinkedListTwo){

}

input:
LinkedListOne = 2->5->7->9
LinkedListTwo = 1->3->4->10

output : 1->2->3->4->5->7->9->10



Hopefully, everyone will have solved these questions on their own, I'll try to solve them in more than one language though depending on the time we might only cover one.