### ss6364's blog

By ss6364, history, 9 months ago, ,

Hi all, I am trying to solve this question,I got some logic and implemented it but getting WA on test case 11. Here is my code.

Don't know whats wrong with my logic or code as I have tried many cases by myself, for all of them I got the correct output.

•  » » » 9 months ago, # ^ | ← Rev. 4 →   0 So all you do is try to leave the $K$ most common numbers in place and move the rest? Why didn't you just say so? (As an aside, the comments in your code aren't super useful, because they describe what you are doing instead of why you're doing them. The most useful thing for you would've been to say the first sentence in this comment. But it's nice you put in the effort anyway.)Anyway, this is wrong because it ignores the part about choosing $l$ and $r$, moving the numbers smaller than $l$ to $l$ and the numbers larger than $r$ to $r$. Consider the following test case: you can accommodate 4 different numbers and the numbers are: 1 1 1 1 1 2 3 4 5 5 5 5 5 Your solution claims that we only need to change one value. But really, we have to change five values.
•  » » » » 9 months ago, # ^ |   0 thank you very much, I'm more clear about my logic now and also got why the other AC solution uses prefix sum array. Its really silly mistake, I'll try to never repeat this again in future.the comments in your code aren't super useful, because they describe what you are doing instead of why you're doing themI'll take care of it in future. Thanks for your help.