GMEDIAN - Editorial(Unofficial)

The problem with your code arises in counting the number of good subsequences of even length.
One of your failed test case will be
A=1 2 2 2 2 3
Output should be 54
Your code’s output : 46
I suggest you to read the editorial completely. I’ve shown the same test case as an example to pass subtask 2

1 Like

Your code fails for sequence having multiple duplicates. Also, you can’t just add the min(left,right) directly to your ans. I suggest you to read the example I’ve given in the editorial above

In [1,2,2,3,3] -> [1,2,2,3] (with 3 of index 3) and [1,2,2,3] (with 3 of index 4), both are good subsequence

Its late, but thanks!:slight_smile: