Solution #138 - Daniel/Edited - 14.03.2025#30
Open
danzang100 wants to merge 2 commits intoDijkstra-Edu:masterfrom
Open
Solution #138 - Daniel/Edited - 14.03.2025#30danzang100 wants to merge 2 commits intoDijkstra-Edu:masterfrom
danzang100 wants to merge 2 commits intoDijkstra-Edu:masterfrom
Conversation
JRS296
requested changes
Mar 21, 2025
Member
JRS296
left a comment
There was a problem hiding this comment.
Solution looks good, but Kindly improve the explanation.md file just like the other PR's (Markdown + Step by Step breakdown + Time and Space Complexity explanation)
Comment on lines
+1
to
+14
| Goal was to create a deep copy of a linked list with a random pointer along with the next pointer. | ||
|
|
||
| Initial approach was to create a vector of the linked list to be able to map indices to each of the nodes. | ||
| Then a hashmap to map the Node to its corresponding index. | ||
| Then a vector to store the new nodes. | ||
| Then a hashmap to map the indices of the new nodes to their indices. | ||
| Finally the random pointer of each node would be mapped to the corresponding index of the prev list, using both hashmaps. | ||
|
|
||
| Optimal approach is to use a single hashmap to just | ||
| map old node to new node in the first traversal. | ||
| Second traversal to find the next and random pointers of the new nodes based on the values of the old node keys. | ||
|
|
||
| Interweaved approach creates new nodes and inserts them in the new list. | ||
| By traversing the interweaved list, we can assign the next node of the old node's random pointer to the new node's random pointer. One more traversal would be required to separate the two. However, I haven't implemented that approach here. |
Member
There was a problem hiding this comment.
Solution looks good, but Kindly improve the explanation.md file just like the other PR's (Markdown + Step by Step breakdown + Time and Space Complexity explanation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solution and Explanation uploaded.