What i am doing wrong in the first code?

The problem is PALINT.

Here is my unaccepted answer: WA

Here is accepted answer Right Answer

The only difference in both is the way, i am taking the variable max. In right answer i took max, and first set it’s value to the maximum frequency in the subarray. while in wrong answer i took max=0 and set it’s value only when i am checking for maximum frequency after XOR operation.

My doubt is , in RA i will be only skipping to the good part i.e. more than the greatest frequency that has already occurred, while in WA I will be checking for all the value, so shouldn’t the value of max will be automatically set to the maximum.

What is wrong in the way I’m taking variable max in WA?

Thank you!!

Consider this TC:

5 0
2 2 2 2 2

Expected Output:

5 0

Your Output:

5 5

The difference in WA and AC is intermediate changes in max.

  • In AC the max is already set to the maximum occurrence of any element.

  • While in the second one the max is changing while we are traversing the map
    intermediate changes will lead smaller value less than the actual max occurrence to
    change our result.


Thank you, so much…now I got it.

1 Like