Skip to content

Practice Minimum Array Length After Pair Removals

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

Medium#2856
LeetCode Problem

Minimum Array Length After Pair Removals

Problem Statement

nums is sorted in nondecreasing order. In one operation, remove two entries at different positions whose values are strictly different; the remaining entries retain their order. Repeat any number of times. Return the smallest possible remaining length.

Source: Minimum Array Length After Pair Removals on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

# Example 3

Input
nums = [1000000000,1000000000]
Output
2

# Example 4

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

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
nums is sorted in non-decreasing order.

Related LeetCode Problems

Practice more problems similar to Minimum Array Length After Pair Removals.

Review your practice with PhantomCodeAI

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