Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code Addition Request]: I would like to add linked list algorithm, clone linked list with random connection #881

Closed
3 tasks done
SKG24 opened this issue Oct 27, 2024 · 3 comments
Assignees
Labels
Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. gssoc-ext hacktoberfest level1 Status: Assigned💻 Indicates an issue has been assigned to a contributor.

Comments

@SKG24
Copy link
Contributor

SKG24 commented Oct 27, 2024

Have you completed your first issue?

  • I have completed my first issue

Guidelines

  • I have read the guidelines
  • I have the link to my latest merged PR

Latest Merged PR Link

This is my first issue

Project Description

Given a linked list where each node has a next pointer to the next node in the list and a random pointer that can point to any node in the list (or be NULL), create a deep copy (clone) of the list. The cloned list should have nodes with the same values and maintain the same next and random pointers structure as the original list.

Explanation of Solution

  • We will use an unordered_map to store the mapping from each node in the original list to its corresponding node in the cloned list. This will help us efficiently set up the next and random pointers for the nodes in the copied list.

  • Mapping Nodes: In the first traversal, we create a new node for each node in the original list and map it to the original node in the unordered_map.

  • Setting Pointers: In the second traversal, we set the next and random pointers for each cloned node. Using the unordered_map, we can efficiently look up and set these pointers to ensure the cloned list has the same structure as the original.

  • Returning the Cloned Head: Finally, we return the cloned node that corresponds to the original list’s head.

Full Name

Sanat Kumar Gupta (@SKG24)

Participant Role

gssoc-ext, hackoctoberfest

Copy link

🙌 Thank you for bringing this issue to our attention! We appreciate your input and will investigate it as soon as possible.

Feel free to join our community on Discord to discuss more!

@SKG24
Copy link
Contributor Author

SKG24 commented Oct 27, 2024

Please assign this to me

@UTSAVS26 UTSAVS26 added Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. Status: Assigned💻 Indicates an issue has been assigned to a contributor. level1 gssoc-ext hacktoberfest labels Oct 28, 2024
SKG24 added a commit to SKG24/PyVerse that referenced this issue Oct 28, 2024
Clone a linked list where each node has a next pointer and a random pointer that can reference any node or be None.
@SKG24 SKG24 mentioned this issue Oct 28, 2024
21 tasks
UTSAVS26 added a commit that referenced this issue Oct 28, 2024
#881 added clone linked list
Copy link

✅ This issue has been closed. Thank you for your contribution! If you have any further questions or issues, feel free to join our community on Discord to discuss more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contributor Denotes issues or PRs submitted by contributors to acknowledge their participation. gssoc-ext hacktoberfest level1 Status: Assigned💻 Indicates an issue has been assigned to a contributor.
Projects
None yet
Development

No branches or pull requests

2 participants