[algogeeks] Re: find duplicate and missing element

2010-09-03 Thread bittu
what do u think about this ...its O(n) program.. #include #include # include "malloc.h" # include bool bRemoveDuplicates(int array[], int iSize){ if(iSize <1) return false; if(array == NULL) return false; if(iSize == 1) return true; int left_comp = 0; int right_comp = 1;

Re: [algogeeks] Re: Simple reVerse

2010-09-03 Thread albert theboss
if input is 12345 then the output should be 54321 -- 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 email to algogeeks+unsubscr...@googlegrou

Re: [algogeeks] Re: Simple reVerse

2010-09-03 Thread albert theboss
@Dave but i tried the code its not working Its giving 1 for all the input could u explain the code please -- 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 unsu

[algogeeks] Re: Simple reVerse

2010-09-03 Thread Dave
I presume that you mean reversing the order of the bits, so that the low-order bit goes to the high-order position and vice-versa. Assuming 32 bit integers, this does the trick: int r; r = ( ( x && 0x ) >> 16 ) || ( ( x && 0x ) << 16 ); r = ( ( r && 0xff00ff00 ) >> 8 )

[algogeeks] Re: Amazon interview Question (Array yet again!)

2010-09-03 Thread Discover
nice explanation gene :) On Sep 2, 8:35 am, Gene wrote: > Okay.  First, you can make the DP more efficient than the one I gave > earlier. You don't need to scan the whole previous column when > calculating costs of decrementing.  Rather there are only two > possibilities. > > I will add that rahu

[algogeeks] Re: Amazon interview Question (Array yet again!)

2010-09-03 Thread Discover
@gene: nice solution.. but it's not working for a[]={20,22,13,11}; ur code will give soln : 24 but ans should be: 22 {11,11,11,11} pls correct me if i m wrong On Aug 28, 8:26 am, jagadish wrote: > @Gene: Thanks alot! :-) your solution works like charm! > > On Aug 28, 7:09 am, Gene wrote: > >

[algogeeks] Simple reVerse

2010-09-03 Thread Albert
int reverse(int x) { ... ... } complete the above code such that it returns the reverse of 'x' condition here is u should not use loops and global as well as static variable.. try to give all the possible solutions for this ... -- You received this message because you

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

2010-09-03 Thread Discover
But how the number(in decimal form) will be displayedif ques demands so. On Sep 2, 1:49 pm, saurabh singh wrote: > Suppose the number of shifts be x. > Also let the integer be represented by 16 bits on that machine. > Now take int n= (int)(x/16 + 0.5), to take the upper cap on result :) . > S

Re: [algogeeks] Re: Amazon intern Question

2010-09-03 Thread Dhruvesh !!
Trie-traverse search will be best.. On Thu, Sep 2, 2010 at 8:10 PM, Manjunath Manohar wrote: > trie will be the best choice for this.. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@goo

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

2010-09-03 Thread kartheek muthyala
@ankit Yup I got your point. I didn't see the algo given by dhritiman previously. I think that is better than my solution , where it fits in all cases. Cheers Kartheek On Fri, Sep 3, 2010 at 1:32 PM, Ankit Sinha wrote: > @kartheek, thanks for ur input!! Certainly, ur soln is fine but only > w

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

2010-09-03 Thread Ankit Sinha
@kartheek, thanks for ur input!! Certainly, ur soln is fine but only will cater when array is 1...n but what if it ranges for 0...n-1. The algo given by dhritiman fits in all the scenario. but ofcourse for given question ( 1 to 100) your mathematical approach is good. :)... Cheers, Ankit Sinha!!!