Skip to content

Practice Find the Median of the Uniqueness Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3134
LeetCode Problem

Find the Median of the Uniqueness Array

Problem Statement

You are given an integer array nums. The uniqueness array of nums is the sorted array that contains the number of distinct elements of all the subarrays of nums. In other words, it is a sorted array consisting of distinct(nums[i..j]), for all 0 <= i <= j < nums.length. Here, distinct(nums[i..j]) denotes the number of distinct elements in the subarray that starts at index i and ends at index j. Return the median of the uniqueness array of nums. Note that the median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the smaller of the two values is taken.

Source: Find the Median of the Uniqueness Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3]
Output
1

# Example 2

Input
nums = [3,4,3,4,5]
Output
2

# Example 3

Input
nums = [4,3,5,4]
Output
2

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Find the Median of the Uniqueness Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.