TIP102 Unit 5 Session 1 Advanced (Click for link to problem statements)
TIP102 Unit 5 Session 2 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Established a set (2-3) of test cases to verify their own solution later.
- Established a set (1-2) of edge cases to verify their solution handles complexities.
- Have fully understood the problem and have no clarifying questions.
- Have you verified any Time/Space Constraints for this problem?
next
pointers.HAPPY CASE
Input: Nodes with values "K.K. Slider", "Harriet", "Saharah", "Isabelle"
Output: "K.K. Slider -> Harriet -> Saharah -> Isabelle"
Explanation: The nodes are linked in the correct order.
EDGE CASE
Input: A single node with value "Isabelle"
Output: "Isabelle"
Explanation: The list contains only one node.
Match what this problem looks like to known categories of problems, e.g. Linked List or Dynamic Programming, and strategies or patterns in those categories.
For Linked List problems, we want to consider the following approaches:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create nodes and link them using their next
pointers to form the desired linked list.
1) Create the node `kk_slider` with the value "K.K. Slider".
2) Create the node `harriet` with the value "Harriet".
3) Create the node `saharah` with the value "Saharah".
4) Create the node `isabelle` with the value "Isabelle".
5) Set `kk_slider.next` to `harriet`.
6) Set `harriet.next` to `saharah`.
7) Set `saharah.next` to `isabelle`.
⚠️ Common Mistakes
next
pointer for a node, resulting in a broken list.Implement the code to solve the algorithm.
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
# For testing
def print_linked_list(head):
current = head
while current:
print(current.value, end=" -> " if current.next else "\n")
current = current.next
kk_slider = Node("K.K. Slider")
harriet = Node("Harriet")
saharah = Node("Saharah")
isabelle = Node("Isabelle")
# Link the nodes to form the linked list
kk_slider.next = harriet
harriet.next = saharah
saharah.next = isabelle
# Example Usage:
print_linked_list(kk_slider) # Output: "K.K. Slider -> Harriet -> Saharah -> Isabelle"
Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.
Evaluate the performance of your algorithm and state any strong/weak or future potential work.
Assume N represents the number of nodes in the linked list.