Need help in Mixcolor



I am trying to solve MIXCOLOR and my code passes all the given test cases also the one’s that I am giving it but it is still giving me WA on codechef judge. Please help me in finding the error in my code or my understanding.
My code:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	int t;
	while(t --)
	    long long int n;
	    long long int a[n];
	    for(long long int i=0;i<n;i++)
	    long long int  max = a[n-1];
	    long long int c = 0;
	    for(long long int i=1;i<n;i++)
	        if(a* == a[i-1])
	            a* = (a* + max) % 1000000000;
	            max += a* % 1000000000;
	return 0;


U need to make changes in a[i-1] not in a* and after that u will get write verdict.

i have made changes in ur solution u caan view and pls upvote


And the reason is that a* need to be compared to a[i+1] as we need to change all the repeating element;
ex 2 2 2 3 by ur code it will change a[1] and it won’t be then equal to a[2] which is also 2.


if we u still face problem ask freely


Thanks brother… I just don’t get how is that making a big difference… I was updating a* since I thought a[i-1] was already a unique color… Please correct me if I am wrong…


when u sort array u get all those no together which are not unique like 1 2 2 2 3 3 7 7 so if u update a* in place of a[i-1] then u r gonna miss which are a[i+1].
we can easily understand it by example as here a[1]==a[2] so if u update a[2] then u will miss a[3] which is also 2(in this case);
a[3] and a[1] will remain same.


if u r still confused then let me tell u another approach to his question this question was never meant to update value it just need us to count the no of repeating element after sorting (like 2 2 2 2 so answer would be 3).and ur code in another way


ur code in another way has also passed all the verdict


wooah… thanks brother.