MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / findsum

Method findsum

SubarrayWithZeroSum.java:3–20  ·  view source on GitHub ↗
(int arr[],int n)

Source from the content-addressed store, hash-verified

1class Solution{
2 //Function to check whether there is a subarray present with 0-sum or not.
3 static boolean findsum(int arr[],int n)
4 {
5 // declare a set data structure
6 HashSet<Integer> res = new HashSet<>();
7 // Variable to calculate sum
8 int sum=0;
9 // Traversing the array
10 for(int i=0;i<n;i++)
11 {
12 res.add(sum);
13 sum+=arr[i];
14 if(res.contains(sum))
15 {
16 return true;
17 }
18 }
19 return false;
20 }
21}

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected