linked list - get length - save other information about contents Two pointers - ‘race car’ strategy with one regular pointer, and one fast pointer Dummy node - helpful for preventing errors when returning ‘head’ (merging lists, deleting from lists)
solve the problem Can you create any ‘magic’ helper methods that would simplify the solution? (ie : getLength(), reverse() ) Talk through different approaches you can take, and their tradeoffs Be able to verbally describe your approach and explain how an example input would produce the desired output
start by understanding the question and running through an example 1->2->3->4->5, n = 2 return 1->2->3->5 Let’s assume we start without any time / space constraints. So our goal is to figure out ANY kind of solution to produce the right answer Any other questions??
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array -> We can also take a pass to get the length of the linked list
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array -> We can also take a pass to get the length of the linked list Plan : What are some different ways we can solve this problem?
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array -> We can also take a pass to get the length of the linked list Plan : What are some different ways we can solve this problem? 1) We can store the elements in an array, get the length of the array, and then rebuild our list excluding the nth to last node
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array -> We can also take a pass to get the length of the linked list Plan : What are some different ways we can solve this problem? 1) We can store the elements in an array, get the length of the array, and then rebuild our list excluding the nth to last node 2) We can follow the first idea, but instead of storing things in an array, remove the reference to the nth to last node the second time we iterate through the list
Are there any special techniques that we can use to help make this easier? -> We can take a first pass through the linked list to store the elements in an array -> We can also take a pass to get the length of the linked list Plan : What are some different ways we can solve this problem? 1) We can store the elements in an array, get the length of the array, and then rebuild our list excluding the nth to last node 2) We can follow the first idea, but instead of storing things in an array, remove the reference to the nth to last node the second time we iterate through the list What would be the space / time complexity of our solution?
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2)
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3.
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0)
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0) As we iterate through the list.. at node 1 -> numberOfNodesSeen = 0
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0) As we iterate through the list.. at node 1 -> numberOfNodesSeen = 0 at node 2-> numberOfNodesSeen = 1
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0) As we iterate through the list.. at node 1 -> numberOfNodesSeen = 0 at node 2-> numberOfNodesSeen = 1 at node 3 -> numberOfNodesSeen = 2 -> at this point we need to set node 2’s next to be node 3’s next!
1) make initial pass through linked list to get length 2) make second pass to remove any reference to nth to last node Let’s draw out how this might work with an example Given linked list 1->2->3, n = 1 (we want to return 1->2) First pass, we get length = 3. Since n = 1, that means we want to remove the 3 -1 = 2 node (with index starting at 0) As we iterate through the list.. at node 1 -> numberOfNodesSeen = 0, previousNode = null at node 2-> numberOfNodesSeen = 1, previousNode = 1 at node 3 -> numberOfNodesSeen = 2, previousNode = 2 -> we set previousNode.next = node.next (node 3’s next = null)
timekeeper - Breakout rooms will close at 11:30 am PT - Take a 5 min break right before then! - Open the Course Portal and go to this week’s Session #2 tab - Read the At a Glance - Start with the Icebreaker! - If your pod needs help, post a message in the @se102-help-fall21 slack channel and tag @se102-tas
team figure out what to work on in the next 3-6 months? - How does the team tackle tech debt? - What is a typical release process? - Weekly? Biweekly? - How does the team prepare for releases? - How is the release monitored afterwards? - Are there oncall schedules?