Skip to content

Commit 4541c05

Browse files
committed
Largest subarray with 0 sum
1 parent 54d1185 commit 4541c05

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.*;
2+
3+
public class larSarrSumzero
4+
{
5+
public static void main(String[] args)
6+
{
7+
Scanner sc=new Scanner(System.in);
8+
int n=sc.nextInt();
9+
int arr[]=new int[n];
10+
for(int i=0;i<n;i++)
11+
{
12+
arr[i]=sc.nextInt();
13+
}
14+
15+
int lmin=0;
16+
for(int i=0;i<n;i++)
17+
{
18+
int sum=0;
19+
int l=0;
20+
for(int j=i;j<n;j++)
21+
{
22+
sum+=arr[j];
23+
l++;
24+
if(sum==0)
25+
{
26+
if(l>lmin)
27+
{
28+
lmin=l;
29+
}
30+
}
31+
32+
}
33+
34+
}
35+
System.out.println("Length of subarray with zero sum "+lmin);
36+
37+
38+
}
39+
}

0 commit comments

Comments
 (0)