Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-28 Thread Rajeev Kumar
Hi All, Algorithm :(as ankur suggested above) 1)Assume given array is a[]; 2)construct a temporary array of size a.length+1.Insert '0' as first element in temp(to simplify the edge conditional checks) 3)temp array contains sum of elements upto index(i) of that position. 4)Create a hashmap and

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-28 Thread Tushar Bindal
can't we include -9 , 3 , 1, 5 , 0 as a possible sub array? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-28 Thread Ankur Khurana
it will be answer as per my algo . On Thu, Jul 28, 2011 at 7:39 PM, Tushar Bindal tushicom...@gmail.comwrote: can't we include -9 , 3 , 1, 5 , 0 as a possible sub array? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-28 Thread Rajeev Kumar
@Tushar : We can do it...thing is to modify the getCombinations() method in the program to select any two instead of selecting two elements side by side... On Thu, Jul 28, 2011 at 7:31 AM, Tushar Bindal tushicom...@gmail.comwrote: yeah i was just confirming that it is meant to be

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-28 Thread Tushar Bindal
yup i got it now. nice code -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-21 Thread sagar pareek
thank you kamakshii :) it is really helpful On Thu, Jul 21, 2011 at 1:28 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: use sum calculated in 2nd array as index for hashing..and index for second array as value of hashing; for example original array:20 , -9 , 3 , 1, 5 ,

[algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread SAMMM
Nice solution dude . Like that one -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread sagar pareek
@Kamakshi... answer must be sub sequence of the array anyone pls explain ANKUR's approach On Thu, Jul 21, 2011 at 12:12 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: for the above example,there are more possible sub arrays like -9,9 -9,0,9 On Thu, Jul 21, 2011 at 12:06 AM, sagar

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread Pankaj
*Contiguous elements* On Thu, Jul 21, 2011 at 12:12 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: for the above example,there are more possible sub arrays like -9,9 -9,0,9 On Thu, Jul 21, 2011 at 12:06 AM, sagar pareek sagarpar...@gmail.comwrote: @ankur pls explain through an

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread sagar pareek
@Pankaj did u get ankur's approach? On Thu, Jul 21, 2011 at 12:16 AM, Pankaj jatka.oppimi...@gmail.com wrote: *Contiguous elements* On Thu, Jul 21, 2011 at 12:12 AM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: for the above example,there are more possible sub arrays like -9,9 -9,0,9

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread varun pahwa
nice solution by ankit. but can anyone tell if we were to find sequence that may or may not be contiguous. On Thu, Jul 21, 2011 at 12:22 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: a little mistake in ankur's solution 20 , -9 , 3 , 1, 5 , 0, -6 , 9 20 , 11,14,15,20,20(instead of

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread Kamakshii Aggarwal
@sagar: i read contiguous afterords therefore i deleted my post... and for ankur's approach : original array:20 , -9 , 3 , 1, 5 , 0, -6 , 9 array after addition:20 , 11,14,15,20,20,14,23 now when u hash second array elements then u fill find collision at value 14 and 20 this means terms b/w 1st

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread sagar pareek
pls anyone explain it Please please please On Thu, Jul 21, 2011 at 12:37 AM, varun pahwa varunpahwa2...@gmail.comwrote: nice solution by ankit. but can anyone tell if we were to find sequence that may or may not be contiguous. On Thu, Jul 21, 2011 at 12:22 AM, Kamakshii Aggarwal

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread Kamakshii Aggarwal
@sagar: i read contiguous afterwards therefore i deleted my post... and for ankur's approach : original array:20 , -9 , 3 , 1, 5 , 0, -6 , 9 array after addition:20 , 11,14,15,20,20,14,23 now when u hash second array elements then u fill find collision at value 14 and 20 this means terms b/w 1st

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread sagar pareek
how collision occur at 14 and 20 actually i m not getting hash function Thanks in advance On Thu, Jul 21, 2011 at 12:39 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: @sagar: i read contiguous afterwards therefore i deleted my post... and for ankur's approach : original array:20 , -9 , 3

Re: [algogeeks] Re: Contiguous subarray with sum zero

2011-07-20 Thread Kamakshii Aggarwal
use sum calculated in 2nd array as index for hashing..and index for second array as value of hashing; for example original array:20 , -9 , 3 , 1, 5 , 0, -6 , 9 array after addition:20 , 11,14,15,20,20,14,23 according to above example hashing will be like this k[20]=0; k{11]=1; k[14]=2; k[15]=3;