This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
There is a greedy approach to the problem, since there is an important thing mentioned in the question, which says, that you can insert a number as large as anything.
So, you can simply iterate through the given array, and maintain a count of the sum of the segment you are currently in. If any sum gets repeated, means, you have found a segment with sum 0, and hence you would insert a very big number in the segment, so that the sum of that segment never becomes zero. This enables us to ignore this segment, and everything before, and start a new segment from this position and repeat the process.
Maintain an answer variable and increase it by 1, every time you had to insert a very big number. And this the answer.
Screenshots(Attach 2 screenshots of your own input and output) -
Checklist:
Eg - If your code follow the below guidelines. Kindly change [] to [x]
All the conditions should be fulfilled for considering your code for merging -
[X] I have mentioned the question as comment in my solution file.
[X] My code follows the guidelines of this project.
[X] I have performed a self-review of my own code.
[X] I have commented my code.
[X] My code gives the correct output.
[X] I confirm that I have not copied the code from anywhere. In case its found that I have copied even after successful merge then I can be banned from the repository and hacktoberfest.
[X] I affirm that I strictly follow contributing guidelines and code of conduct.
2) Form 2
Issue Id you have worked upon -
Kindly write your answer here
Checklist:
Eg - If your code follow the below guidelines. Kindly change [] to [x]
All the conditions should be fulfilled for considering your Pull Request for merging -
[] I have performed a self-review of my documentation.
[] I affirm that I strictly follow contributing guidelines and code of conduct.
Choose your form and fill it -
1. Form 1(C++ Solution contributors)
2. Form 2(C++ Documentation Contributors)
1) Form 1
Issue Id you have worked upon -
436
Briefly explain your program logic -
There is a greedy approach to the problem, since there is an important thing mentioned in the question, which says, that you can insert a number as large as anything. So, you can simply iterate through the given array, and maintain a count of the sum of the segment you are currently in. If any sum gets repeated, means, you have found a segment with sum 0, and hence you would insert a very big number in the segment, so that the sum of that segment never becomes zero. This enables us to ignore this segment, and everything before, and start a new segment from this position and repeat the process.
Maintain an answer variable and increase it by 1, every time you had to insert a very big number. And this the answer.
Screenshots(Attach 2 screenshots of your own input and output) -
Checklist:
Eg - If your code follow the below guidelines. Kindly change [] to [x]
All the conditions should be fulfilled for considering your code for merging -
[X] I have mentioned the question as comment in my solution file.
[X] My code follows the guidelines of this project.
[X] I have performed a self-review of my own code.
[X] I have commented my code.
[X] My code gives the correct output.
[X] I confirm that I have not copied the code from anywhere. In case its found that I have copied even after successful merge then I can be banned from the repository and hacktoberfest.
[X] I affirm that I strictly follow contributing guidelines and code of conduct.
2) Form 2
Issue Id you have worked upon -
Kindly write your answer here
Checklist:
Eg - If your code follow the below guidelines. Kindly change [] to [x]
All the conditions should be fulfilled for considering your Pull Request for merging -
[] I have performed a self-review of my documentation.
[] I affirm that I strictly follow contributing guidelines and code of conduct.