can anyone plz point out the mistake in this question of encoder contest

ques link:
soln link:

i am certain that my approach is fine just can’t figure out what’s wrong plz help

Even I had the same problem…

Try this test case :


5 4

5 4 3 3 2

1 2 3 4 2

your code gives 4…expected is 3…as we need to count unique colors on wall (even if they are in different partition)
Just add a set to get correct answer…

ohh! okay thank u so much!!