[algogeeks] Re: Directi Interview Ques

2012-07-30 Thread Lucifer
@Prakhar Jain I believe that the following recurrence shall solve it.. Take an array C[n+1][n+1]... Now, we only need to calculate those C[i][j]'s where i+j is even.. // Assuming 1-based index... Initialization condition... C[0][0]=0; for(int i =0; i =n; i+=2) { C[0][i] = C[0][i-2] +

[algogeeks] Re: Directi Interview Ques

2012-07-30 Thread Lucifer
@small correction: In the initialization condition the loop index i shall start from 2 and not 0.. // for(int i =2; i =n; i+=2) On 30 July, 15:23, Lucifer sourabhd2...@gmail.com wrote: @Prakhar Jain I believe that the following recurrence shall solve it.. Take an array  C[n+1][n+1]...

[algogeeks] Re: Directi Interview Ques

2012-07-30 Thread Lucifer
@vivek.. u can't sort.. its a stable merge... The question is to stably merge the two arrays..the stable merge of the 2 arrays can take place in (2n C n) ways.. 1 of these arrangements will lead to the maximum sum.. We are required to find that sequence/maxsum.. A stable merge in this case is

[algogeeks] Re: Directi Interview Ques

2012-07-23 Thread Rahul Kumar
http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_cs;action=display;num=1280183627 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: Directi Interview Ques

2012-07-21 Thread a g
@ anshu - should it not be like this : f( x(i, n), y(j, n) ,0) = max( { x[i] * x[i+1] + max ( f( x(i+2, n), y(j, n), 0) , f( x(i+2, n), y(j, n), 1) ) }, { x[i] * y[j] + max ( f( x(i+1, n), y(j+1, n), 1 ), f( x(i+1, n), y(j +1, n), 0 ) } ); On Mon, Jul 16, 2012 at 2:15 AM, Anshu Mishra

Re: [algogeeks] Re: Directi Interview Ques

2012-07-17 Thread Amit Jain
Awesomely done :) +1 On Mon, Jul 16, 2012 at 2:15 AM, Anshu Mishra anshumishra6...@gmail.comwrote: two arrays are suppose x[n], y[n]; take a function f( x(i, n), y(j, n) , 0) -- taking x[i] as a first element of merged array then max sum; f( x(i, n), y(j, n), 1) -- taking y[j] as a first

Re: [algogeeks] Re: Directi Interview Ques

2012-07-17 Thread Amit Jain
Please see *stable merge *in question. On Sun, Jul 15, 2012 at 2:04 AM, sengar.mahi sengar.m...@gmail.com wrote: @naveen : 3*7+2*9+1*3 =42 is not maximum.. sum of the product would me maximum wen, i guess, most weighted elements are adjacent like in this case if c={1,2,3,3,7,9} 1*2 + 3*3 +

Re: [algogeeks] Re: Directi Interview Ques

2012-07-15 Thread Anshu Mishra
two arrays are suppose x[n], y[n]; take a function f( x(i, n), y(j, n) , 0) -- taking x[i] as a first element of merged array then max sum; f( x(i, n), y(j, n), 1) -- taking y[j] as a first element of merged array then max sum; f( x(i, n), y(j, n) ,0) = max( { x[i] * x[i+1] + f( x(i+1, n),

[algogeeks] Re: Directi Interview Ques

2012-07-14 Thread Navin Gupta
As the final array contains element in stable-order, at any time we have 3 options for choosing the elements from A B. 1- A[i] A[i+1] 2- A[i] B[I] 3- B[i] B[i+1] we will choose that pair whose product is maximum. For ex:- A-2,1,3 B-3,7,9 C- 3,7,2,9,1,3 Its a linear time solution with

Re: [algogeeks] Re: Directi Interview Ques

2012-07-14 Thread sengar.mahi
@naveen : 3*7+2*9+1*3 =42 is not maximum.. sum of the product would me maximum wen, i guess, most weighted elements are adjacent like in this case if c={1,2,3,3,7,9} 1*2 + 3*3 + 7*9=74 (maximum ) thus this question is just merging both strings such resultant (here C) is in sorted order which can

Re: [algogeeks] Re: Directi Interview Ques

2012-07-14 Thread Arunachala Karthik
O(n2) Time and O(n2) space solution - 1. Total of (n2 + 2n - 2) products possible with given combinations - (n - 1) times (n + 1) and once n for the first array for the last element; total of (n -1) products for 2nd array -therefore (n -1)(n +1) + n + (n-1) = n2 + 2n - 2. Products to be