For N = 1000, the answer will contain 10.
Since you’ve represented the answer using a string though, what gets stored is char('0' + 10) which is :, so you end up printing that instead of 10.
Store the answer in an array/vector and I think you will get AC.
It’s an unfortunate mistake.
@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 .
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??
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
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