Re: [algogeeks] [SPOJ] ZSUM

2011-10-20 Thread Wasif Hossain
Just a MINOR change. please change the RED line(I've marked it below) in your code by the following line: *return (x*((z*z)%MOD))%MOD;* and enjoy an *ACCEPTED *verdict.* * *Wasif Hossain** * B.Sc. Student of Final Semester, Computer Science and Engineering(CSE), Bangladesh University of

Re: [algogeeks] Amazon Ques Suggest Algo

2011-10-20 Thread SUMANTH M
- Take another sum array which contains sums of original array at each index, here sum[0] = a[0]; sum[1] = a[0] + a[1] ;...sum[i]=a[0]+a[1]+...a[i]; - Traverse the sum array and search for duplicates. ex: a[] = {1,2,-4,-3, 6 ,-3}; s[] = { 1,3,-1,-4,2,-1 }; In the sum array we have

Re: [algogeeks] Amazon Ques Suggest Algo

2011-10-20 Thread anshu mishra
index = 0 1 2 3 4 5 6 ar = 0 1 2 -4 -3 6 -3 sumar = 0 1 3 -1 -4 2 -1 first index where we get the number which has already appeared in sumar will be the last index of sub array whose sum will be zero and (index of first apperance of this number + 1) in sumar will be the start index.

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-20 Thread anshu mishra
@Ravindra To check the particular number square can be written as sum of two squares or not. If it has any prime factor x such that x % 4 == 1 then only. Now about time complexity. suppose u have given array is. 10 6 13 9 17 4 18 12 1 5. now u can easily skip the numbers(1, 4, 6, 9, 12, 18);

[algogeeks] Re: Amazon Ques Suggest Algo

2011-10-20 Thread Navneet
+1 for Sumanth's solution. On Oct 20, 12:03 pm, anshu mishra anshumishra6...@gmail.com wrote: index  =  0 1 2  3  4 5  6 ar       =  0 1 2 -4 -3 6 -3 sumar =  0 1 3 -1 -4 2 -1 first index where we get the number which has already appeared in sumar will be the last index of sub array whose

Re: [algogeeks] what is the use of fflush ?

2011-10-20 Thread ravindra patel
Excerpt from The C Programming Language by Kerninghan Ritchie - *int fflush(FILE *stream) - *On an output stream, fflush causes any buffered but unwritten data to be written; *on an input stream, the effect is undefined*. So fflush was never meant for stdin. - Ravindra On Sun, Oct 9, 2011 at