wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> rearrange array
(Message started by: m_aakash on Mar 19th, 2008, 7:09am)

Title: rearrange array
Post by m_aakash on Mar 19th, 2008, 7:09am
Given two arrrays, one with actual elements, other with 0,-1 or 1 values. 0 says that the corresponding element in the other array is at correct position. 1 indicates the corresponding element in the other array should move forward. -1 indicates move backward. if it is possible to satisfy these constraints, return the new array or return -1.

input =    { 1, 2, 4, 5, 7, 8 }
critique ={ 0, 1, 0, -1, 1, -1 }
output = { 1, 5, 4, 2, 8, 7 }

input =    { 1, 2, 4, 5, 7, 8 }
critique ={ 0, 1, 0, -1, -1, 0 }
output = { 1, 5, 4, 7, 2, 8 }

Title: Re: rearrange array
Post by towr on Mar 19th, 2008, 7:56am
Seems to be the same as this topic (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_cs;action=display;num=1204174018).

Title: Re: rearrange array
Post by m_aakash on Mar 19th, 2008, 10:05am

on 03/19/08 at 07:56:28, towr wrote:
Seems to be the same as this topic (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_cs;action=display;num=1204174018).


thanks towr for providing the link.



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