Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code javascript: Count the minimum number of integers that must be deleted from an array so that no two integers occur the same number of

code javascript:
Count the minimum number of integers that must be deleted from an array so that no two integers occur the same number of times.
Task description
An array A consisting of N integers is given. Our goal is to obtain an array in which every value occurs a unique number of times. We only consider integers that appear at least once in the resulting array. To achieve the goal, we can delete some integers from A. What is the minimum number of integers that must be deleted from A so that every remaining value occurs a unique number of times?
Write a function:
function solution(A);
that, given an array A consisting of N integers, returns the minimum number of integers that must be deleted from it so that every remaining value occurs a unique number of times.
Examples:
1. Given A =[1,1,1,2,2,2], the function should return 1. We can delete one occurrence of 1 or one occurrence of 2. After this operation, one value will occur three times and the other one two times.
2. Given A =[5,3,3,2,5,2,3,2], the function should return 2. After deleting number 3 twice, the remaining elements of the array are [5,2,5,2,3,2]. In this array no two numbers occur the same number of times.
3. Given A =[127,15,3,8,10], the function should return 4. All elements of the array occur exactly once. We have to delete all but one element.
4. Given A =[10000000,10000000,5,5,5,2,2,2,0,0], the function should return 4.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..200,000];
each element of array A is an integer within the range [0..1,000,000,000].

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions