[algogeeks] Re: adobe question

2012-10-21 Thread apsalar
You could update fibb[n] before returning fib(n-1) + fib(n-2) int fib(int n) { if ( n = 1 ) { fibb[1]=n; return n; } if (fibb[n] ! = 0 ) { //return fibs(n-1)+fibs(n-2); } On Sunday, October 21, 2012 7:46:43 AM UTC-4, rahul sharma wrote:

[algogeeks] Re: adobe question

2012-10-21 Thread apsalar
You could store fibs[n-1] + fibs[n-2] in fibb[n] before returning. int fib(int n) { if ( n = 1 ) { fibb[1]=n; return n; } if(fibb[n] != 0) { return fibb[n]; } fibb[n] = fibs[n-1] + fibs[n-2]; return fibb[n]; //return fibs(n-1)+fibs(n-2); }

Re: [algogeeks] Re: adobe question

2012-10-21 Thread Jaspreet Singh
here's an O(lgn) soln : matrix form of fib : http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form and then use the divide and conquer for calculating (A)^n in O(lgn). Thanks On Sun, Oct 21, 2012 at 7:10 PM, rahul sharma rahul23111...@gmail.comwrote: I have implemented this code below:-

[algogeeks] Re: adobe question help

2012-09-13 Thread Navin Gupta
int temp = {[1(j-+1)]i-1}; Here temp is a number with all the bits set between positions i j [both inclusive] temp = ~temp; N = N temp; // here we are clearing all the bits of N from position i to j temp = temp | M; // now we are taking the bit pattern from M into temp

Re: [algogeeks] Re: adobe question help

2012-09-13 Thread Ashish Goel
this is from KR exercise :) Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Sep 12, 2012 at 4:14 PM, Navin Gupta navin.nit...@gmail.com wrote: int temp = {[1(j-+1)]i-1}; Here temp is a number with all the bits set between positions i j

[algogeeks] Re: adobe question help

2011-10-02 Thread ravi ojha
in the first loop the value of k shuld vary from 0 to j-i. On Oct 1, 7:26 am, rahul sharma rahul23111...@gmail.com wrote: You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N

Re: [algogeeks] Re: adobe question help

2011-10-02 Thread rahul sharma
yeah u r ryt. On Sun, Oct 2, 2011 at 4:20 PM, ravi ojha rbojha...@gmail.com wrote: in the first loop the value of k shuld vary from 0 to j-i. On Oct 1, 7:26 am, rahul sharma rahul23111...@gmail.com wrote: You are given two 32-bit numbers, N and M, and two bit positions, i and j.

Re: [algogeeks] Re: adobe question help

2011-10-02 Thread rahul sharma
can u tell in this we have to set i and j also or only between elements say if i=2 and j=6 then whether we should set bit no 2,3,4,5,6, or 3,4,5 acc. to me its 2,3,4,5,6, and ur logic also give that answer plz tell?? On Sun, Oct 2, 2011 at 4:38 PM, rahul sharma

[algogeeks] Re: Adobe Question

2011-01-10 Thread Aviral Gupta
Replace 0 by -1 and make a[i] as sum of all a[j] j=i Now u need to find the subarray with sum 0 For this u can use array of size 2n denoting -n to n Now at sum u can update array of 2n size with the index just found corresponding to that sum Overall complexity O(n) Regards

[algogeeks] Re: Adobe Question

2011-01-10 Thread Aviral Gupta
Replace 0 by -1 and make a[i] as sum of all a[j] j=i Now u need to find the subarray with sum 0 For this u can use array of size 2n denoting -n to n Now at sum u can update array of 2n size with the index just found corresponding to that sum Overall complexity O(n) Regards

Re: [algogeeks] Re: Adobe Question

2011-01-10 Thread vinayan c
make a running sum with -1 instead of 0 keep an array of the running sum.in the array find out the indexes with with equal sum at farthest distance...those two will be the bouding points of maximum subsesequence.. On Sun, Jan 9, 2011 at 10:19 PM, bittu shashank7andr...@gmail.com wrote: i

[algogeeks] Re: Adobe Question

2011-01-09 Thread bittu
i think its DP Problemstill thinking on the soultion.. @ankur..ur approach nearly matches to mine..what i thought..but we need actual solution.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Adobe question

2010-10-26 Thread Lily Aldrin
@ Saurabh XOR method will also work under the assumption that array 2 will contain the same elements as array 1 except one element. On Fri, Oct 22, 2010 at 9:01 PM, Saurabh Koar saurabhkoar...@gmail.comwrote: @Mohit: Rajan clearly sais that array 2 contains all the elements of array1 + 1 extra

Re: [algogeeks] Re: Adobe question

2010-10-22 Thread MOHIT ....
@rajan array 1 - {2,2} array 2 - { 4,4,1} according 2 you .. unique is {(4+4+1)-(2+2)}=5 ? but it is not... -- 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

Re: [algogeeks] Re: Adobe question

2010-10-22 Thread Saurabh Koar
@Mohit: Rajan clearly sais that array 2 contains all the elements of array1 + 1 extra element..Your example doesn't do so...By the way the method suhhested by Rajan is not universal.It is not necessary that array 2 will contain the same elements as array 1...XOR method will be the best... -- You

[algogeeks] Re: Adobe question

2010-10-21 Thread Dave
XOR all of the elements of the array. The duplicated elements cancel each other out, and the result is the unduplicated element. Dave On Oct 21, 9:05 am, bittu shashank7andr...@gmail.com wrote: You have an array consisting of 2n+1 elements, n elements in it are married, i.e they occur twice in

[algogeeks] Re: Adobe question

2010-10-21 Thread Dave
I think that you are saying that the second array contains all of the elements in the first array, plus one additional element. If this is the proper interpretation, then just XOR all of the elements of both arrays and the result is the additional element. Dave On Oct 21, 9:12 am, bittu

Re: [algogeeks] Re: Adobe question

2010-10-21 Thread rajan goswami
@Dave - There could be another good solution instead of XOR. If below interpretation of the problem is correct, Array1 - contains n elements ( order is irrelevent) Array2 - contains all n elements of Array1 ( order is irrelevent) + 1 extra element which is unique from all n elements of Array1.

Re: [algogeeks] Re: Adobe Question

2010-09-25 Thread Nikhil Jindal
The answer would be: (log1+1) + (log2+1) + (log3+1) + (log4+1) + ... + (log(n-1)+1) which is equal to: (log1+log2+log3+...+log(n-1)) + (n-1) == *log((n-1)!) + (n-1)* where, log everywhere is assumed to be in base 2 *This according to me will be the final answer!* * * *Cheers* *Nikhil Jindal * On

[algogeeks] Re: Adobe Question

2010-09-24 Thread Ashutosh
n*ceil(log_2n) On Sep 24, 9:23 am, Krunal Modi krunalam...@gmail.com wrote: But, how was it derived ? :( What is the intuition behind ? :( :( -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Adobe Question

2010-09-24 Thread nishaanth
@Dave sorry i didnt see k n (thought it was k=n) The intuition i guess would be at every powers of 2 it increases by 1 i.e 1=0 2=1 3=1+1=2 4=2+2=4 see the increase of 2 here 5=4+2=6 6=6+2=8 7=8+2=10 8=10+3=13 ..see the increase of 3 here i guess we can work on from here On Fri, Sep

[algogeeks] Re: Adobe Question

2010-09-24 Thread SVIX
what's the datatype of j? mathematically speaking, the while loop is infinite for every j0... On Sep 23, 6:19 am, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ; kn ; k++){   j=k;   while(j0){      j=j/2;   } } How many times while loop gets executed (for any n) ? I don't want

[algogeeks] Re: Adobe Question

2010-09-23 Thread Dave
@Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1, where a^b is a to the power b. Dave On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ; kn ; k++){   j=k;   while(j0){      j=j/2;   } } How many times while loop gets executed (for any n) ? I don't want

Re: [algogeeks] Re: Adobe Question

2010-09-23 Thread coolfrog$
@ Dave can u explain ur answer...plz.. On Thu, Sep 23, 2010 at 8:55 AM, Dave dave_and_da...@juno.com wrote: @Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1, where a^b is a to the power b. Dave On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote: for(k=1 ;

[algogeeks] Re: Adobe Question

2010-09-23 Thread Krunal Modi
@Apoorve : All are integer int. @Dave: Can you explain how u arrived at this equation ? -- 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

[algogeeks] Re: Adobe Question

2010-09-23 Thread Dave
How did I arrive at this equation? I entered the first few terms of the sequence, 0,1,3,5,8,11,14,17, into the On-Line Encyclopedia of Integer Sequences, at http://www.research.att.com/~njas/sequences/, and read the Formula section of the result. It is amazing what you can find on the internet if

[algogeeks] Re: Adobe Question

2010-09-23 Thread Krunal Modi
But, how was it derived ? :( What is the intuition behind ? :( :( -- 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

Re: [algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-30 Thread rahul patil
check this code . if it works correctly ? reverse the ans and you will find the no converted in target base.(ignore extra 0's) #include stdio.h #include stdlib.h #include string.h #define MAX 10 int main() { int i; int b1,b2; char no1[MAX] = ,no2[MAX] = ; int *result = (int *) calloc

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-29 Thread Ukil
@above Can't you please explain a bit? On Aug 29, 10:15 am, rahul patil rahul.deshmukhpa...@gmail.com wrote: Check out my solution. Hope u are looking for this, Take  a no   136 (base7 = 76 decimal )  convert to base 5 (ans shld be 301) start from left side 1*7^2= 49/5^2 =  1 (rem 24)    

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-29 Thread luckyzoner
@Rahul : I know that u are using table of base b2 in base b1 and then dividing the number using the table ...but the real problem is to code it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-28 Thread rahul patil
Check out my solution. Hope u are looking for this, Take a no 136 (base7 = 76 decimal ) convert to base 5 (ans shld be 301) start from left side 1*7^2= 49/5^2 = 1 (rem 24)- | ^ 10 3*7 + 24 = 45 /5 = 19 (rem 0)

[algogeeks] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-20 Thread bittu
can u provide solution of base conversion problem discussed abpve -- 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] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-20 Thread bittu
@ Rahul in Tejus Can u provide solution base conversion problem discussed above -- 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] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-18 Thread luckyzoner
I would again say that you don't have to use any intermediate base while converting. -- 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] Re: Adobe Question : Convert a number given in base B1 to a number in base B2 without using any intermediate base

2010-08-18 Thread Gene
Since any modern computer is going to do all its operations in base 2, this is impossible. You have to allow the base that the computer uses for fundamental arithmetic. On Aug 18, 8:33 am, luckyzoner luckyzo...@gmail.com wrote: I would again say that you don't have to use any intermediate base