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.
Also please help me in understanding this submission for the same why he used prefix sum and how it is different from my logic. Please help me. Thanks.
Can you please briefly explain what everything in your code does? People aren't interested in debugging unreadable and unannotated code.
Anyway this is how you can get out of those situations: make a program to generate thousands of small test cases. Make another "naive" solution (or in this case you can copy someone's accepted solution) and compare the outputs on the small test cases. This way you're bound to find a small test case where your program gives the wrong output. Then you can find out where your logic is wrong.
Sorry sir, I've updated it. Please have look at it.
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:
Your solution claims that we only need to change one value. But really, we have to change five values.