Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Least Number of Unique Integers after K Removals (medium)
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

Given an array of integers arr and an integer k, return the least number of unique integers remaining after removing exactly k elements from the array.

Examples

Example 1

  • Input: arr = [5, 5, 4, 3, 2, 3, 2, 3, 3, 2], k = 6
  • Expected Output: 1
  • Justification: After removing 4, all 5, and three instances of 2, the updated array will be [3, 3, 3, 3]. It will have only 1 unique element.

Example 2

  • Input: arr = [7, 7, 7, 8, 8, 9], k = 2
  • Expected Output: 2
  • Justification: Removing two instances of the 8, or 1 instance of 8 and 1 of 9, there will be 2 unique elements in the array.

Example 3

  • Input: arr = [1, 2, 2, 3, 4, 3], k = 4
  • Expected Output: 1
  • Justification: You can remove 1, 4 and either both instances of 2 or 3, and the final array will be [2, 2] or [3, 3], based on which element you have removed from the array.

Constraints:

  • 1 <= arr.length <= 10<sup>5</sup>
  • 1 <= arr[i] <= 10<sup>9</sup>
  • 0 <= k <= arr.length

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself