Can we assume the output array is a new array and we can distort the
originial array???
On Fri, Sep 30, 2011 at 9:14 AM, praveen raj praveen0...@gmail.com wrote:
Take two array... one will take care of left products... and othr will take
care of right product.. at any index
@nitin ..
Output array is not a new array ... you can do anything to input array ..
~raju
On Fri, Sep 30, 2011 at 1:24 PM, Nitin Garg nitin.garg.i...@gmail.comwrote:
Can we assume the output array is a new array and we can distort the
originial array???
On Fri, Sep 30, 2011 at 9:14 AM,
@raju - so it means the input array should be distorted to give the output
array.
Are you sure about it? i doubt if its possible.
On Fri, Sep 30, 2011 at 11:24 PM, raju nikutel...@gmail.com wrote:
@nitin ..
Output array is not a new array ... you can do anything to input array ..
~raju
On
char A[] = { 1,2,3,4,5 };
int algo(int b, int i) {
if(i == sizeof(A)) { return 1; }
int c = A[i];
int f = algo(b*c, i+1);
A[i] = b*f;
return f*c;
}
On Thu, Sep 29, 2011 at 8:26 AM, raju nikutel...@gmail.com wrote:
Given an integer array. { 1,2,3,4,5 }
Compute array
Is the array Sorted ?
On Thu, Sep 29, 2011 at 4:56 PM, raju nikutel...@gmail.com wrote:
Given an integer array. { 1,2,3,4,5 }
Compute array containing elements
120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4)
We shouldn't use division operator( / )
Time complexity O(n) ..
maintain two arrays one left array having value left[i] =
a[0]*a[1]*a[2].a[i-1] and one right array having value
right[i]=a[i+1]*[i+2]a[n] and then to get
ans[i]...ans[i]=left[i]*right[i]
On Thu, Sep 29, 2011 at 8:16 PM, Ankur Garg ankurga...@gmail.com wrote:
Is the array Sorted ?
whats the running time? isn't it O(n2) ?
On Thu, Sep 29, 2011 at 8:54 PM, UTKARSH SRIVASTAV
usrivastav...@gmail.comwrote:
maintain two arrays one left array having value left[i] =
a[0]*a[1]*a[2].a[i-1] and one right array having value
right[i]=a[i+1]*[i+2]a[n] and then to get
//use dynamic programming approach
//it is O(n) time and O(1) space
#includestdio.h
#define N 5
void main()
{
int a[N]={1,2,3,4,5},i;
int prod1[N];
int p=1;
for(i=0;iN;++i)
{
prod1[i]=p;
p*=a[i];
}
int prod2[N];
p=1;
for(i=N-1;i=0;--i)
{
prod2[i]=p;
p*=a[i];
}
int products[N];
check this http://www.geeksforgeeks.org/archives/7527
time O(n)
space O(n)
--
Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
http://gplus.to/amolsharma99
are the algorithm instance always a sequence incremented by one?
On Thu, Sep 29, 2011 at 8:26 AM, raju nikutel...@gmail.com wrote:
Given an integer array. { 1,2,3,4,5 }
Compute array containing elements
120,60,40,30,24 (2*3*4*5,1*3*4*5, 1*2*4*5, 1*2*3*5, 1*2*3*4)
We shouldn't use division
Given array A.
Compute array B such that
B[0] = 1;
for(i = 1; i n; i++)
B[i] = B[i-1]*A[i-1]
now,
mul = 1;
for (i = n-2; i =0; i--){
mul = mul*A[i];
B[i] = B[i]*mul;
}
On Fri, Sep 30, 2011 at 2:18 AM, Hatta tmd...@gmail.com wrote:
are the algorithm instance always a sequence
sorry, one mistake...
mul = mul*A[i];
it should be
mul = mul*A[i+1]
On Fri, Sep 30, 2011 at 2:57 AM, Piyush Grover piyush4u.iit...@gmail.comwrote:
Given array A.
Compute array B such that
B[0] = 1;
for(i = 1; i n; i++)
B[i] = B[i-1]*A[i-1]
now,
mul = 1;
for (i = n-2; i =0;
Take two array... one will take care of left products... and othr will take
care of right product.. at any index left[i]=A[i-1]*left[i-1] starting
from left and right[i]= A[i+1]*right[i+1] starting frm right……
--
You received this message because you are subscribed to the Google Groups
13 matches
Mail list logo