Unique Frequency Checker

Hashmap Frequency Strings Unique Holiday

Problem Description

Given an array of strings representing holiday greetings, write a function that determines whether the number of occurrences of each greeting is unique. In other words, no two different greetings should have the same frequency.

For example, given the array:

["Merry", "Cheerful", "Merry", "Happy", "Cheerful", "Joyful"]

The frequencies are:

  • "Merry" : 2
  • "Cheerful" : 2
  • "Happy" : 1
  • "Joyful" : 1

Since both frequencies 2 and 1 occur more than once, the function should return false.

Your task is to implement the function uniqueFrequencies that returns true if all greeting frequencies are unique, and false otherwise.

Hint: Use a hashmap (or dictionary) to count occurrences, and then another data structure (like a set) to check for uniqueness of the frequency values.

Function Signature

Your function should have the following signature (shown here in a language-agnostic way):

function uniqueFrequencies(greetings: string[]) -> boolean

Example

Input:

["Happy", "Joy", "Happy", "Cheerful"]

Counts:

  • "Happy": 2
  • "Joy": 1
  • "Cheerful": 1

Since the frequency 1 is not unique, the function should return false.

Starter Code

Below is some starter code to help you begin your solution.