#2856

Minimum Array Length After Pair Removals

medium · 27.1% accepted · 422 likes · top 5%

array · hash table · two pointers · binary search · greedy · counting

⊣ practice⊣ open on leetcode ↗

Description

Given an integer array num sorted in non-decreasing order.

You can perform the following operation any number of times:

- Choose two indices, i and j, where nums[i] < nums[j].

- Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.

Return the minimum length of nums after applying the operation zero or more times.

Solution