Unit 6 Session 1 (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?
HAPPY CASE
Input: Assignment statement to create a linked list
Output: 4 -> 3 -> 2
Explanation: Proper creation of the linked list from head to tail with the values 4, 3, and 2 respectively.
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 construction problems, we want to consider the following approaches:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Construct a linked list by directly linking nodes through a nested constructor pattern.
1) Start by creating the last node of the list with a value of 2 and no subsequent node.
2) Create the middle node with a value of 3 and link it to the last node.
3) Create the head node with a value of 4 and link it to the middle node.
⚠️ Common Mistakes
Implement the code to solve the algorithm.
Node(4, Node(3, Node(2)))
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.
O(1)
because we are simply creating three nodes and linking them, which involves a constant amount of work regardless of input size.O(1)
because the space used does not scale with input size, it remains constant for the three nodes.