InterviewBit Academy Test A

Hello Guys can you please share the approach for 2nd question of interviewbit academy Test A which was getting maximum distinct elements by picking any 3 elements and discarding maximum and minimum.Also for 4th question as well which was count of distinct (l,r) pairs such that after performing operation del(l,r) l<=r the array becomes non-decreasing.
Since the test was 2 days ago so the link is now unavailable.

It was just an observation question. Suppose a number x is repeated y number of times, then if y is odd -> there will be only one x left because others will cancel themselves and if y is even two times of x will be left.
Lets understand with an example,
Suppose: 2 2 2 2 2

I’m picking first three 2’s, two 2’s will be discarded and the remaining elements will be 2 2 2, Now again from this, only one 2 will be left.
Similarly if you do this for even number of elements, only two numbers of x will be left.

So the resulting array will be, either the element is two times or once. Now it was to observe how they will cancel each other.