Where am I wrong in problem CodeChef: Practical coding for everyone?
My solution link is CodeChef: Practical coding for everyone
Where am I wrong in problem CodeChef: Practical coding for everyone?
My solution link is CodeChef: Practical coding for everyone
Though I was unable to solve problem but I can tell you that your code fails on
1
4
0 0 0 0
This problem was based on exception cases caused due to A[i]=0 , I felt 
Oh yes bro you are correct even all the cases where first 4 elements are 0 and rest are anything else is also failing. Thanks bro
For n == 3 there are few more cases you need to take into consideration. For example:
3
1 0 2
You can make it good with the following operations:
1
1 2 3
Have a look at my submission: CodeChef: Practical coding for everyone
@omeshwar_05 from what I can see your n==3 case is not complete.
You can look at my n==3 case here.
ps: my code is a bit messy there could be better ways to generalize it.
All fine but I can’t understand what u did here and what logic did u apply.
There’s easy way to handle n=3 without any ugly casework. After applying 1st operation, the seq doesn’t change in any further operations. So, you’re left with checking only 4 options-
check if the array is already good. If yes print 0.
else try 3 cases- operation on all 3 indices individually. If array becomes good in any of those, then print that operation otherwise print -1.
Your prob was so great that I couldn’t think of anything
Okay, let me explain (I’ll do my best)
n <= 3 I just hard-coded the output based on different inputsn > 4, you can always follow the below strategy to get a good sequence:
-1
nzi. Now you can take another index nzi2 such that it is nzi-2 or nzi+2.arr[nzi] ^ arr[nzi2]
arr[nzi] == arr[nzi2], then all the even indices are filled with zero. You can use nzi and any even index to make all the values at odd indices equal to arr[nzi]. Thus you get a good sequence.arr[nzi] != arr[nzi2], then all the even indices are filled with some value say X. You can use any two even indices and make all values at odd indices equal to 0. Thus you get a good sequence.nzi is even, you use nzi and nzi2 to first fill the odd indices and then fill even indices similar to steps 4 and 5