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.
MIT License
46
stars
132
forks
source link
himanshi added Subarray_with_zero_sum.cpp in the GeekForGeeks folder #472
Kindly write your answer here
In this program we have to find the subarray form the given array whose sum is zero.
My program has a time complexity of O(n) and space Complexity of O(n)
The basic approach for this program is to first find the prefix sum of the array and store it in the map and if the sum of any subarry gets repeated that means that between those two numbers lies the subarray with the sum zero and hence we are able to find the solution for the question
Another case to consider is that if the number itself in the array is zero that means the sum of that single subarray is zero.
This was my approach for the question.
Screenshots(Attach 2 screenshots of your own input and output) -
Attach here
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 -
Kindly write your answer here
437
Briefly explain your program logic -
Kindly write your answer here In this program we have to find the subarray form the given array whose sum is zero. My program has a time complexity of O(n) and space Complexity of O(n) The basic approach for this program is to first find the prefix sum of the array and store it in the map and if the sum of any subarry gets repeated that means that between those two numbers lies the subarray with the sum zero and hence we are able to find the solution for the question Another case to consider is that if the number itself in the array is zero that means the sum of that single subarray is zero. This was my approach for the question.
Screenshots(Attach 2 screenshots of your own input and output) -
Attach here
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.