Re: [algogeeks] least common ancestore bst

2013-05-27 Thread Mangal Dev Gupta
static Node LCA(Node root, int a, int b) { if (root == null) return null; if (root.getData() == a || root.getData() == b) return root; Node root1 = LCA(root.getLeft(), a, b); Node root2 = LCA(root.getRight(), a, b); if (root1 !=

Re: [algogeeks] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-27 Thread Mangal Dev Gupta
Hi Don, instead of searching 1 at all places we can use this : while(n!=0){ count++; n = n n-1; } On Fri, May 17, 2013 at 6:55 PM, Don dondod...@gmail.com wrote: Counting the set bits in one integer is not the problem which was asked. However, I think that something like this is both

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-12 Thread Mangal Dev Gupta
was not first but somewhere in between, the loop will break there when coming from behind and size will have the index right? Why do we need to store elem in first position according to your code? On Sun, Oct 7, 2012 at 3:01 PM, Mangal Dev Gupta dev@gmail.comwrote: *@Dave while( arr

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-08 Thread Mangal Dev Gupta
*@Dave while( arr[--size] != elem );* *Exception will come when it will encounter a[-1]* *i dont know if this loop will ever end... very poor solution i will say * On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq the.um...@gmail.com wrote: Well actually, I've just gone through Dave's code