Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Binary search over the answer.
For a given <code>x</code>, you need to check if <code>x</code> is the median, to the left of the median, or to the right of the median. You can do that by counting the number of sub-arrays <code>nums[i…j]</code> such that <code>distinct(num[i…j]) <= x</code>.
Use the sliding window to solve the counting problem in the hint above.