-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Create subset_sum.cpp #1517
Create subset_sum.cpp #1517
Conversation
@fhlasek I have added self test cases. Please have a look. P.S. It returns the number of subsets with given sum since storing all the subsets and then returning them was taking much more space leading to bad space complexity so I preferred returning an integer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, simple, clear and well documented and tested. Thanks!
@fhlasek done the changes. Pl have a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks great now! Happy to approve. Consider some suggestions about the documentation. A better description of the algorithm might be helpful.
Co-authored-by: Filip Hlasek <[email protected]>
Co-authored-by: Filip Hlasek <[email protected]>
I just commited the suggestions, then why there is statement like "Swastyy dismissed fhlasek’s stale review via a32b32f 3 minutes ago" in the thread? |
Also I can't see the approved tick. Did I made some mistake while committing suggestions? P.S. I am newbie in open source and I don't know how these silly mistakes happens 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I guess that was my mistakes. I haven't realised that this repo is set up to invalidate the approval after code changes are committed. Here is another ✅ 👍🏼
Co-authored-by: Filip Hlasek <[email protected]>
@fhlasek how to get 1 more approvel? 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@mishraabhinn Can you see this PR. It already got 1 approval, 1 more will be appreciated 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be output if the sum =2 and arr=[1,1,1] @Swastyy
I think you can add a specific description, subset_sum can cause ambiguity that whether this algorithm is for continuous subarrays or non continuous subarrays. |
Yea, it will return 3. I have taken a similar test case (Test 4) with arr = [3,3,3,3] and sum = 6 |
Generally subsets contain both the continuous and non-continuous subarrays. I will add it in the description. 👍 |
@mishraabhinn we cannot take unsigned int as data type because we are taking negative weights array in the test case |
int8_t |
Now I feel like using int is not a good practice. Does it matters when we are adding our own test cases |
I will tell you one thing, writing code for any problem is simple. But what we should learn is to write clean code. You should write code in such a way that if you/someone someday come back to the code, you don't have to go line by line in the code to understand it, rather seeing the name of file , function name and variable name code should speak itself. |
Yea, this used to happen with me. But now I make proper doc. 😃 |
@Panquesito7 Pl review this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @Swastyy! Thank you for your patience, dedication, and contributions to our community! 👍 🎉
Description of Change I have created subset_sum.cpp to return the number of subsets(both continuous and non-continuous subarrays) whose sum equals the given sum value in case if there doesn't exists any subset with given sum the function will return 0.
Checklist
Notes: