SarthakKeshari / CPP-Questions-and-Solutions

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

Closed Himanshi1207 closed 2 years ago

Himanshi1207 commented 2 years ago

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 firstss secondss


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 -


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 -