Re: [algogeeks] Re: Finding non-repetitive element from an Array with complexity n

2011-04-17 Thread ashish agarwal
to get the non repeating element we have to travese array atleast once.so Time complixity has to minimum o(n).as I suppose.. The XOr solution will fail because odd number will be there... Hashing itself require o(n) space in worst case. On Mon, Apr 18, 2011 at 12:40 AM, sravanreddy001

Re: [algogeeks] Re: Lets C Who Really Loves Perfect Square .................

2011-02-24 Thread ashish agarwal
@dave..Can you please explain your logic .. Regards, Ashish On Thu, Feb 24, 2011 at 6:32 AM, Dave dave_and_da...@juno.com wrote: Try this: int i,k,n; long long j,nsq; for( n = 31623 ; n 10 ; ++n ) { nsq = (long long)n * (long long)n;

Re: [algogeeks] Pairwise Sum Array

2011-02-24 Thread ashish agarwal
I think.. As like no are a,b,c,d,e so sum will be a+b,a+c,a+d,a+e,b+c,b+d,b+e,c+d,c+e,d+e; so maximuum value will be d+e which is last element of array given take last three value 1.c+d 2.c+e 3.d+e eq(1)-eq(2)=d-e; solving it with 3rd eq will give d and e and with these value we can get other

Re: [algogeeks] Pairwise Sum Array

2011-02-24 Thread ashish agarwal
There must be another good solution..please let me know . Thanks On Thu, Feb 24, 2011 at 5:09 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: I think.. As like no are a,b,c,d,e so sum will be a+b,a+c,a+d,a+e,b+c,b+d,b+e,c+d,c+e,d+e; so maximuum value will be d+e which is last

Re: [algogeeks]

2011-02-24 Thread ashish agarwal
The basic solution which is coming to the mind is to covert string first palindrome and apply livishthein distance to both string(original one and changed string) to check how many substiutions you require for the palindrome. On Wed, Feb 23, 2011 at 9:11 PM, radha krishnan

Re: [algogeeks] Re: Large File Millions of Records

2011-02-16 Thread ashish agarwal
take an array of 10 ,travese the whole rcord and apply min heap on these 10 elements. as like first 10 no will be there and we apply minheap so we will get minimun num in these 10 number..If next numbe is greater then minimun no in array ..we will replace it and apply minheap ... On Thu, Feb 17,

Re: [algogeeks] Re: String Operation

2011-02-16 Thread ashish agarwal
trie tree will be better to implement On Thu, Feb 17, 2011 at 11:07 AM, Jammy xujiayiy...@gmail.com wrote: Greedy, always choose the remaining one that is the lexicographically smallest since choose any other way will yield a lexicographically greater one. void concante(char **strings, int

Re: [algogeeks] Tree problem(Amazon)

2011-02-07 Thread ashish agarwal
jalaj back to algogeeks.. On Mon, Feb 7, 2011 at 6:09 PM, rahul rai raikra...@gmail.com wrote: Are all the integers positive only ? On 2/7/11, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: you are given a bst where each node has a int value , parent pointer , and left and right pointers

Re: [algogeeks] [Athena 2011]

2011-01-12 Thread ashish agarwal
didn't get your question dude On Wed, Jan 12, 2011 at 10:39 PM, Pratik Bhadkoliya pkbhadkol...@gmail.comwrote: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) is an ordered list of positive integers Let magic(value) denote the number of such ordered lists that exist such that

Re: [algogeeks] 10 most repeating words

2010-10-21 Thread ashish agarwal
use a array of 10 and apply min heap On Thu, Oct 21, 2010 at 7:05 PM, Vinay... vinumars...@gmail.com wrote: how do u find 10 most repeating words on a large file containing words in most efficient way...if it can also be done using heapsort plz post ur answers.. -- You received this

Re: [algogeeks] Re: 2 elements with sum = x

2010-10-10 Thread ashish agarwal
take two pointer p and q p=a[0] and q=a[n-1]; sum=p+q; if(sumx) q--; if (sumx) p++; On Sun, Oct 10, 2010 at 6:54 PM, Rohit email.rohit.n...@gmail.com wrote: On Oct 10, 10:48 am, Shravan shravann1...@gmail.com wrote: http://ideone.com/D5W2y Good :). What if array is unsorted. What

Re: [algogeeks] Re: Largest Rectangle in a binary Matrix:

2010-10-10 Thread ashish agarwal
This question was asked in google interview one solution for this question is DP make a matrix p (all rows and columns are initialized to zero) if(a[i][j]==1]{ p[i][j]=min(p[i-1][j],p[i,j-1],p[i-1][j-1]]+1; } else p[i][j]=0; f find p[i][j] such that its has max value. On Sun, Oct 10, 2010 at

Re: [algogeeks] Re: Largest Rectangle in a binary Matrix:

2010-10-10 Thread ashish agarwal
ohh..I think my solution will work on square not on rectangles. On Sun, Oct 10, 2010 at 8:13 PM, Mridul Malpani malpanimri...@gmail.comwrote: @ ashish agarwal ur solution will not work on this : 10101 0 1 11000 On Oct 10, 6:59 pm, ashish agarwal ashish.cooldude...@gmail.com

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-11 Thread ashish agarwal
the principles of Kadane's algo : http://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane.27s_algorithm On Mon, Sep 6, 2010 at 3:50 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: int max=0,sum=0,begin=0,end=0,i=0; for(int j=0 to n){ sum+=a[j]; if(maxsum){ max=sum; begin=i

[algogeeks] LIS in nlogn

2010-09-11 Thread ashish agarwal
Can anybody tell me least increasing sub sequence in nlogn please try to provide code in C -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] LIS in nlogn

2010-09-11 Thread ashish agarwal
can you give link for this On Sat, Sep 11, 2010 at 6:10 AM, Nikhil Agarwal nikhil.bhoja...@gmail.comwrote: This has been discussed already.Please refer that post I have provided the actual code . On Sat, Sep 11, 2010 at 3:20 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: Can

Re: [algogeeks] Excellent Compilation of Interview Questions

2010-09-10 Thread ashish agarwal
aham aham On Fri, Sep 10, 2010 at 12:56 PM, Shashank Krishna sasan...@gmail.comwrote: Excellent Compilation of Interview Questions Visit http://www.cracktheinterview.org/ -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-07 Thread ashish agarwal
://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane.27s_algorithm On Mon, Sep 6, 2010 at 3:50 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: int max=0,sum=0,begin=0,end=0,i=0; for(int j=0 to n){ sum+=a[j]; if(maxsum){ max=sum; begin=i; end=j; } else if(sum0){ i=j+i; sum=0

Re: [algogeeks] Yahoo Question:Greatest Sub-sequential sum

2010-09-06 Thread ashish agarwal
int max=0,sum=0,begin=0,end=0,i=0; for(int j=0 to n){ sum+=a[j]; if(maxsum){ max=sum; begin=i; end=j; } else if(sum0){ i=j+i; sum=0; } return sum; i will tell the starting index and j will tell ending index; o(n); correct me if i am wrong On Mon, Sep 6, 2010 at 1:42 PM, bittu

Re: [algogeeks] fork() problem

2010-09-04 Thread ashish agarwal
I think 4. On Sat, Sep 4, 2010 at 9:03 AM, Maria lydwin.ma...@gmail.com wrote: How many processes are created in this snippet? Main() { Fork(); Fork() fork () || fork (); Fork (); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Re: find duplicate and missing element

2010-09-02 Thread ashish agarwal
In this method overflow will be there..if number is just bigger...so by doing XOR we can get missing number and repeated number . take xor of all element of array and take this xor with array[1...n] So we get xor of two numbers. now get set bit of this xor and proceed. On Thu, Sep 2, 2010 at

Re: [algogeeks] Re: Take 5 digit number and find 2 power that number.............

2010-09-02 Thread ashish agarwal
I think it will be 1x On Wed, Sep 1, 2010 at 10:53 PM, Yan Wang wangyanadam1...@gmail.com wrote: Maybe you misunderstand the question. The question is how to compute 2^X where 0 = X = 9? How? On Wed, Sep 1, 2010 at 10:48 PM, Ruturaj rutura...@gmail.com wrote: a 5 digit number is

Re: [algogeeks] Re: Google Interview Question

2010-08-22 Thread ashish agarwal
but addition also should be in array On Sun, Aug 22, 2010 at 3:05 AM, arpit agarwal erarpitagar...@gmail.comwrote: Just find out the max and 2nd max in n + log(n) -2 steps and add them. there is no need for sorting as such -- You received this message because you are subscribed to the

Re: [algogeeks] How to find two missing numbers from an unsorted continuous natural numbers array [only use O(1) space and O(n) time]

2010-08-12 Thread ashish agarwal
take the sum of array and product. if they were present then sum will be n(n-1)/2 and product will be n!. make two eq of a+b and a-b with these values and get the num On Thu, Aug 12, 2010 at 5:26 AM, vijay auvija...@gmail.com wrote: How to find two missing numbers from an unsorted continuous

Re: [algogeeks] Median of two arrays..

2010-08-05 Thread ashish agarwal
a[1n] b[1...m] find median of two array say n1 and m1..if n1m1 then median of both array can't be in in region a[n1..n] and b[1...m1]so now search space is reduced ..and we continue like this untill we find median. On Thu, Aug 5, 2010 at 6:37 AM, AlgoBoy manjunath.n...@gmail.com wrote:

Re: [algogeeks] Find the duplicate

2010-08-05 Thread ashish agarwal
travse array and check that if(a[i]==a[i+1]||a[i]==a[i+2]); if more then n/2 no are there then that condition will satisfy ...adjust with boundary condition On Thu, Aug 5, 2010 at 6:36 AM, AlgoBoy manjunath.n...@gmail.com wrote: an array in which n/2 elements are unique...and the remaning n/2

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread ashish agarwal
I think use bfs ... On Thu, Jul 29, 2010 at 11:26 AM, irfan naseef irfannase...@gmail.comwrote: On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal ashish.cooldude...@gmail.com wrote: please explain q ..i didnt understand On Thu, Jul 29, 2010 at 11:01 AM, irfan irfannase...@gmail.com

Re: [algogeeks] algorithm to draw a line

2010-07-12 Thread ashish agarwal
draw a line or equation of a line? On Mon, Jul 12, 2010 at 4:38 PM, Anand anandut2...@gmail.com wrote: 2 coordinate points p(x,y)and q(x,y) are given and write an algorithm to draw aline -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] graph

2010-07-12 Thread ashish agarwal
@anand ..can you explain it more with example On Mon, Jul 12, 2010 at 10:19 AM, Anand anandut2...@gmail.com wrote: topological sort would cover every vertex once. The path given by Topological sort would be the answer. We can also calculate the vertices given by topological sort and compare

Re: [algogeeks] Phone Numbers Yet Again!!!

2010-07-12 Thread ashish agarwal
@amit..can you little explain this On Mon, Jul 12, 2010 at 4:50 PM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: this can be done in O(n) using DP: for (i=n-1;i=0;i--){ dp[i]=max(dp[i+2],dp[i+3]); // usual if (a[i]==a[i+1]) // excellent size 2

Re: [algogeeks] solutions?

2010-07-11 Thread ashish agarwal
solution for topcoder all available but not others On Sun, Jul 11, 2010 at 2:19 AM, venkat kumar svenkatkuma...@gmail.comwrote: are solutions available for problems in spoj,uva,codedhef,topcoder,etc.etc.?pls tell me tnkyou -- You received this message because you are subscribed to the

Re: [algogeeks] Sort

2010-07-10 Thread ashish agarwal
for sort you have to traverse array atleast once ..and after it some sorting procedure will come. On Fri, Jul 9, 2010 at 12:55 PM, Devendra Pratap Singh dpsingh.ii...@gmail.com wrote: plz write a code to Sort n integer in the range 1 to n^2 in O(n) -- You received this message because

Re: [algogeeks] Yahoo

2010-07-04 Thread ashish agarwal
it will be 1:1 because probability of guy is 1/2+1/2*1/2+1/2*1/2*1/2.=1 and girls and boys has same probability On Sun, Jul 4, 2010 at 6:00 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: yeah 1:1 On Sun, Jul 4, 2010 at 4:57 PM, Amit Jaspal amitjaspal...@gmail.comwrote: it will be

Re: [algogeeks] amazon question

2010-07-03 Thread ashish agarwal
We can do 4 type of treversal. If we do inorder then we will get sorted array .If we do an inorder traversal then we would get a sorted list which if we convert into a BST would again become a list and we would loose out on the original structure of the tree. and same will be happen with post