What is wrong in my code ?

Please tell me where is error in my solution for chefham?

I don’t really understand C++ but your code is pretty hard to read through. Try using functions or better yet instead of having so many conditions ( I counted about 20 if’s,else’s and else if’s altogether) why not generalize? You only really need two conditions (if a[x] == b[x],else). but if you still want to use many, comment your code so we can all understand what you were trying to do. Good luck and happy coding. I hope I helped a bit

1

9

2 2 3 1 3 4 4 5 5

Your output:

7

2 1 3 4 4 5 5 2 3

expected:

9

1 5 2 5 2 3 3 4 4

1 Like

Here is one of the inputs where your code is not generating correct ouput

INPUT:

1

7

1 2 1 2 3 3 4

OUTPUT:

6

3 1 2 1 4 3 2

POSSIBLE OP:

7

4 3 2 1 2 1 3

and if N>=5, maximum possible hamming distance is always N

If the input has a adjacent numbers equal and followed by a number at alternate positions your code doesn’t work.

Sample INPUT :
4

5

1 1 2 3 2

5

1 1 2 2 3

5

1 2 1 2 3

5

2 3 2 1 1

Your OUTPUT :

2

1 3 2 1 2

5

2 2 3 1 1

5

3 1 2 1 2

5

1 2 1 2 3

Try figuring out the problem in your code.
Your approach uses lot of assumptions, try out a more generalized.