Search⌘ K
AI Features

Solution: Least Number of Unique Integers after K Removals

Understand how to minimize the number of distinct integers remaining after exactly k removals from an array. Learn to count element frequencies, use a min-heap for efficient access to least frequent elements, and apply this knowledge to remove elements optimally, ensuring the smallest unique integer count remains. This lesson covers the step-by-step solution and analyzes its time and space complexities.

Statement

You are given an integer array, arr, and an integer, k. Your task is to remove exactly k elements from the array so that the number of distinct integers remaining in the array is minimized. Determine the minimum possible count of unique integers after the removals.

Constraints:

  • 11 \leq arr.length 103\leq 10^3

  • 11 \leq arr[i] 105\leq 10^5

  • 00 \leq ...