Re: [algogeeks] Re: Algo for Search in a 2D Matrix

2012-05-17 Thread Anika Jain
there's a solution of O(log n) where 2D matrix has n rows and n columns. Apply binary search for the search on the diagonal. when you are left with just one element after the search apply binary search within that elements row and its column. you will get the element. O(log n+log n+log n). so

Re: [algogeeks] Re: validate bit pattern : MS question

2012-05-17 Thread Ashish Goel
Hello Dave, Was trying this bool OnesZerosOnes(unsigned int n) { if( !(n 1) || !(n = n+1) ) return 0; /*step1*/ n |= n-1;/*step 2*/ return !(n (n+1)); /*step 3*/ } for 1110011 after step 1 it becomes 1110010100=111 after step2 it becomes 111|110=111(all ones)

Re: [algogeeks] Re: validate bit pattern : MS question

2012-05-17 Thread Ashish Goel
got it...super... Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, May 17, 2012 at 8:21 PM, Ashish Goel ashg...@gmail.com wrote: Hello Dave, Was trying this bool OnesZerosOnes(unsigned int n) { if( !(n 1) || !(n = n+1) ) return

Re: [algogeeks] Amazon off campus telephonic interview

2012-05-17 Thread Bhaskar Guthikonda
Usual data structures and algorithmic questions. They love the guys who can do actual coding, instead of blurting it out in pseudo-codes, since its a telephonic interview, I think its going to be different for you. On Wed, May 16, 2012 at 6:37 PM, rishabh shukla rockrishabh.mn...@gmail.com

Re: [algogeeks] Re: storing URL's

2012-05-17 Thread Prakash D
We can still improve this trie idea.. say we have urls like www.google.com www.goodbye.com www.google.com/transliterate www.goodstrain.com/good we can subdivide everything under www.goo I mean we can store each character as a node in a trie and call it like a URL dictionary On Wed, May 16,

Re: [algogeeks] Re: Find Power(N,N),

2012-05-17 Thread Piyush Khandelwal
@ pankaj joshi: Hi ... The following code will do it for you. Go through the code, execute it, if u dont get the logic revert back to me. // code begins.. #includestdio.h #define MAX 1 void factorialof(int); void multiply(int); int length = 0; int fact[MAX]; int main(){ int

Re: [algogeeks] Re: storing URL's

2012-05-17 Thread Prem Krishna Chettri
For the cases where Storing the Value is the only Concern and (Not the Retrieval efficiency), I would Suggest Something called DFA Subset minimization.. Google for it ... and after the final subset as said U can use something called DAWG for the most Most Optimal solution.. On Thu, May 17, 2012

Re: [algogeeks] Interview Question based on histogram

2012-05-17 Thread Bhaskar Kushwaha
It depends on which column you are pouring the water. For example If you choose the shortest column to pour the water then only that column will be filled with water. Please correct me if I am wrong. On Thu, May 17, 2012 at 11:27 AM, Nikhil Agarwal nikhil.bhoja...@gmail.comwrote: Imagine that

Re: [algogeeks] Interview Question based on histogram

2012-05-17 Thread payal gupta
hope this works.. http://ideone.com/XSJRJ On Fri, May 18, 2012 at 8:20 AM, Bhaskar Kushwaha bhaskar.kushwaha2...@gmail.com wrote: It depends on which column you are pouring the water. For example If you choose the shortest column to pour the water then only that column will be filled with

Re: [algogeeks] Re: validate bit pattern : MS question

2012-05-17 Thread Piyush Khandelwal
Hii Can anyone explain to me what this code is doing?? On 17 May 2012 20:36, Ashish Goel ashg...@gmail.com wrote: got it...super... Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, May 17, 2012 at 8:21 PM, Ashish Goel

Re: [algogeeks] Re: validate bit pattern : MS question

2012-05-17 Thread Vishal Thanki
On Sat, Apr 7, 2012 at 11:24 AM, Dave dave_and_da...@juno.com wrote: @Ashgoel: Try this: bool OnesZerosOnes(unsigned int n) {     if( !(n 1) || !(n = n+1) ) return 0;     n |= n-1;     return !(n (n+1)); } Here is how it works: !(n 1) is true if the number has trailing zeros. If