Question: Sort elements by their frequency and index using Hash Table Given an unsorted array, sort its elements by their frequency and index. i.e. -- If

Sort elements by their frequency and index using Hash Table

Given an unsorted array, sort its elements by their frequency and index. i.e.

-- If two elements have different frequencies, then the one that has more frequency should be treated as larger than the other. -- If two elements have the same frequencies, then the one that has less index should be treated as smaller than the other.

For example,

Input: arr = [3, 3, 1, 1, 1, 8, 3, 6, 8, 7, 8]

Output: arr = [3, 3, 3, 1, 1, 1, 8, 8, 8, 6, 7]

std::map is NOT allowed to be used in this project, because it is implemented based on red-black tree instead of hash table.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!