Unique Number of Occurrences

Easy · Arrays & Hashing · Array · Hash Table

Problem

Given an integer array arr, count how many times each distinct value occurs. Return true if no two distinct values occur the same number of times, and false otherwise.

Examples

Input: arr = [1, 2, 2, 1, 1, 3]
Output: true

1 occurs 3 times, 2 twice and 3 once: three different counts.

Input: arr = [1, 2]
Output: false

Both values occur once.

Input: arr = [-3, 0, 1, -3, 1, 1, 1, -3, 10, 0]
Output: true

The counts are 3, 2, 4 and 1.

Constraints

Approaches

Follow-up

If the answer is false, how few elements would you have to delete to make every count unique? And which values have a count that no other value shares?

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…