ODDARY - Editorial

The correct output for the above tc is -
1
1 2
1 2 1
1 2 1 3
1 2 1 3 1
1 2 1 3 1 2
1 2 1 3 1 2 1
1 2 1 3 1 2 1 4
1 2 1 3 1 2 1 4 1
1 2 1 3 1 2 1 4 1 2

Where is my logic or code wrong?

https://www.codechef.com/viewsolution/50123024

Your output for N =12 is
1 2 3 4 3 2 1 2 3 4 3 2
where everything appears twice in the array (1 and 4 appear twice each; 2 and 3 appear 4 times each)

2 Likes

Thank you!!

@knight_rider45 i think it is because of the constraint n<=1000 and the pattern:
If you see the pattern carefully then it goes like:
Position at which 1st occurrence of following numbers spotted:
1: 1
2: 2
3: 4
4: 8
5: 16
6: 32
and so on it follows powers of two.
So, 11 will occur at 1024 position
I guess that’s why there is no use to go beyond .

2 Likes

I took the output for vector size for 10,11 and 12. You can also calculate using a general formula
No. of terms in nth term = 2*(no of terms in n-1th term) + 1

Brother plz help me
1 2 3 2 1 2 3
If I take 1 2 3 2 as subarray then the frequency of 2 will be 2 but it is correct. I can not understand how it is correct brother . can you please explain this matters??

1 Like

frequency of any number is odd for a given subarray then it is correct and in the subarray
1 2 3 2, 1 and 3 have odd occurrences. you just need to avoid the subarray in which all the numbers have even frequencies

1 Like

We are not supposed to have a subarray where all the elements has even frequencies…
So in 1 2 3 2… 2 have even occurence, but 3 and 1 have odd number of occurence

you can also see in subarray 1 2 3 2 1 ,
only 3 has odd number of occurences… it is still valid because all elements are not supposed to have even frequencies at the same time

This was interestingly short :neutral_face: CodeChef: Practical coding for everyone

2 Likes

Good observation,thanks.

please tell me why answer is the first bit one of gray code on Tester’s Solution ?

True , Even the editorial sucks :face_vomiting:

If you have any constructive criticism as to how the editorial can be improved, please let me know :slight_smile:

4 Likes

Check my code if you want exact code as explained in solution.