Array 'A' contains N elements st A[i] =k N
Now,
Iterate over the array.
Let k=A[i]
If A[i] N
then k=A[i] mod N
go to A[k] and write A[k] = A[k] + N
So, lets take a sample array of size 5: 1,2,1,0,4
i=0: k=A[i]=1; A[i] 5; A[1] = A[1] + 5 = A[1] = 7 = A = 1,7,1,0,4
i=1: k=A[i]=7; A[i] 5;
@rahul sharma, i ran this code, it is producing wrong answer :|
check it, http://codepad.org/THv1hJq1
anyone with correct solution?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
I think that the above algo will fail for the following two arrays:
a={2,2,3,3}
b={4,4,1,1}
sum(a)=sum(b);
a^b=0;
len(a)=len(b);
Correct me if i am wrong!
Pranav
On Sun, Jul 3, 2011 at 7:43 AM, varun pahwa varunpahwa2...@gmail.comwrote:
@aditya. xor all elements mean that. take xor of each
, otherwise a simple
greedy approach is to parenthesize all the plus together and then
parenthesize through the multiplication.
For the above example: (3+6)*(7+3)*2
Pranav
On Sat, Dec 18, 2010 at 11:15 PM, snehal jain learner@gmail.com wrote:
Given an expression E of n numbers