wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> Array conversion
(Message started by: sateesp on Aug 29th, 2010, 5:56am)

Title: Array conversion
Post by sateesp on Aug 29th, 2010, 5:56am
Given an array B[] of size N, where each element in B[i] = A[i] + A[(i+1) %N]. Find the array A[]

Example: Given B[] =  {3,5,7,5}
We need to print A[] = {1,2,3,4}

Title: Re: Array conversion
Post by towr on Aug 29th, 2010, 6:42am
There are many possible such arrays if N is even. For example, [-1,4,1,6] would work just as well, or [13,-10,15,-8], or in general [1,2,3,4] + k*[-1,1,-1,1].

So for even N you can just start with A[0]=0, and work from there.



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board