you can create a temp array storing consecutive sum of elements. temp[]={-3,-1,3,-3,-11,-1,10} insert elements in hash if collision occurs then elements between these two indices sum zero.
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
for(i=0;i<7;i++)
ReplyDelete{
for(j=0;j<=i;j++)
{
sum[j]=sum[j]+a[i];
if(sum[j]==0)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
printf("The subarray is from %d to %d",j,i);
this solution has o(n^2) running time,try to optimize it.
ReplyDeleteyou can create a temp array storing consecutive sum of elements.
ReplyDeletetemp[]={-3,-1,3,-3,-11,-1,10}
insert elements in hash if collision occurs then elements between these two indices sum zero.