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

Solved Q22 Generate Parentheses c++ with comments #34

Merged
merged 4 commits into from
Oct 3, 2022

Conversation

aryanayush012
Copy link
Contributor

@aryanayush012 aryanayush012 commented Oct 2, 2022

This is a template on how to fill out a PR properly.

Description

Q23. The optimised approach of the problem - Merge K Sorted Lists, involves the usage of Min-Heap
In c++, Min-Heap is implemented with the help of Priority-Queue
At the begining, we will be storing only K Elements, into our Min-Heap.
We will also have a dummy Node to keep track of the Head of our Merged LinkedList.
Tail pointer will intially point to dummy but keeps on Nodes in order to form the Merged K Sorted LinkedList
After adding first K Elements, we will use a While Loop which runs till our Priority-Queue has not become empty.
Everytime, we will pick the Top Element from the Priority-Queue(which will also be smallest among all K Nodes present). We will make Tail's Next point to that Top Node. Make Tail shift to that Node. And, also add it's Next Node(if it exists)
By repeating the process, we will have our Merged K Sorted LinkedList ready. The Head of that LinkedList will be pointed by Dummy's Next

Q24. if the head is itself NULL then the linked list doesnt exist
if the next of head is null then it contains only one node
in both above senario we have to return our head only
in this step we first create a dummy node with head->next's data
we recursively call the function for next node and it will call further one
we connect our temp node's next to head in order to swap it
finally we return the list

Related Issue

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
💯 Add tests
🔗 Update dependencies
📜 Docs

Testing Steps / QA Criteria

Q22.
Screenshot (132)

Q23.
image

Q24.
image

Copy link
Owner

@DugarRishab DugarRishab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every solution should be inside a folder with the same name. Look at how it is done in the repo.
Also, you have not filled out the template. Please fill out the template properly. It is straight forward.

@DugarRishab
Copy link
Owner

Also, provide the screenshot of the submission page where it shows that your code has passed all the tests. Add this screenshot in the description of this PR on in new comment

@DugarRishab DugarRishab added the invalid This doesn't seem right label Oct 3, 2022
@DugarRishab DugarRishab added hacktoberfest-accepted and removed invalid This doesn't seem right labels Oct 3, 2022
Copy link
Owner

@DugarRishab DugarRishab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work

@DugarRishab DugarRishab merged commit ec4c78c into DugarRishab:main Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants