-
Notifications
You must be signed in to change notification settings - Fork 265
Zodiac Signs
LeWiz24 edited this page Aug 15, 2025
·
2 revisions
Unit 5 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- What is the correct order of the nodes in the linked list according to the given list?
- The nodes must be connected in the order: "aries", "taurus", "gemini", "cancer".
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Sequentially link nodes representing the elements "aries", "taurus", "gemini", and "cancer" to form a linked list.
1) Create a node for each element in the given list and assign each to a variable (node_1, node_2, node_3, node_4).
2) Link each node to the next using the `next` attribute to form a sequence:
- Link `node_1` (aries) to `node_2` (taurus).
- Link `node_2` to `node_3` (gemini).
- Link `node_3` to `node_4` (cancer).
- Incorrectly linking nodes, which could lead to nodes being out of the intended order.
- Failing to link the last node (cancer), which would result in an incomplete list.
node_1 = Node('aries')
node_2 = Node('taurus')
node_3 = Node('gemini')
node_4 = Node('cancer')
node_1.next = node_2
node_2.next = node_3
node_3.next = node_4