InterviewPrepKit

Home / Coding / Algorithm & Data Structure / Arrays & Hashing

Unique Number of Occurrences

easy Original ↗ 00:00

Problem

Given an integer array arr, decide whether every distinct value appears a different number of times. Return True if no two distinct values share the same frequency, False otherwise.

Examples

  • arr = [1, 2, 2, 1, 1, 3]True — 1 appears 3 times, 2 appears twice, 3 appears once: frequencies {3, 2, 1} are all different.
  • arr = [1, 2]False — both values appear exactly once.
  • arr = [-3, 0, 1, -3, 1, 1, 8, 8, -3, 4]False — both -3 and 1 appear 3 times, so two distinct values collide on the same frequency.

Constraints

  • 1 <= arr.length <= 1000
  • -1000 <= arr[i] <= 1000

The bounds are small, so even a quadratic solution passes. A single linear counting pass is cleaner.

Think about it first

Hint 1 The problem is really two sub-problems: first compute the frequency of each distinct value, then check a property of those frequencies.
Hint 2 "No two frequencies are equal" is the same as saying the collection of frequencies contains no duplicates. How do you detect duplicates in one line?
Hint 3 Build a `Counter` of the array, then compare `len(counter.values())` with the size of `set(counter.values())` — if deduplicating shrinks the collection, two values shared a frequency.

Write your solution, then hit Run tests to check it — or get a mock grade from the AI coach.

The coach remembers this session — revise your code and ask again, and it grades your progress. It gives hints, not the answer.
Report a bug