Are All Value Frequencies Different?

Quick Overview

Are All Value Frequencies Different?. Count how often each distinct integer appears in arr. Return true exactly when no two different values have the same occurrence count.

Are All Value Frequencies Different?

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Count how often each distinct integer appears in arr. Return true exactly when no two different values have the same occurrence count. ```cpp class Solution { public: bool uniqueOccurrences(vector<int>& arr); }; ``` ### Examples **Example 1:** ```text Input: arr = [4,4,4,2,2,9] Output: true Explanation: The occurrence counts are3,2,1, all different. ``` **Example 2:** ```text Input: arr = [5,5,-1,-1] Output: false Explanation: Both distinct values occur twice. ``` ### Constraints - The input contains 1 to 1000 integers. - Every value lies in `[-1000,1000]`. ### Contract considerations Negative integers obey the same occurrence-count rule as nonnegative integers. ```hint Read the boundary condition Are integer values themselves required to be different, or are their occurrence counts being compared? ``` ### Boundary reminders Negative integers obey the same occurrence-count rule as nonnegative integers.

Overview: Are All Value Frequencies Different?. Count how often each distinct integer appears in arr. Return true exactly when no two different values have the same occurrence count.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Count how often each distinct integer appears in arr. Return true exactly when no two different values have the same occurrence count.

class Solution {
public:
    bool uniqueOccurrences(vector<int>& arr);
};

Examples

Example 1:

Input: arr = [4,4,4,2,2,9]
Output: true
Explanation: The occurrence counts are3,2,1, all different.

Example 2:

Input: arr = [5,5,-1,-1]
Output: false
Explanation: Both distinct values occur twice.

Constraints

  • The input contains 1 to 1000 integers.
  • Every value lies in [-1000,1000] .

Contract considerations

Negative integers obey the same occurrence-count rule as nonnegative integers.

Boundary reminders

Negative integers obey the same occurrence-count rule as nonnegative integers.