id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

uniqueOccurrences


Given an array of integers, determine whether the number of occurrences (frequency) of each value in the array is unique. In other words, no two distinct values in the array should appear the same number of times. For example, given the input {1, 2, 2, 1, 1, 3}, the frequency counts are: 1 appears 3 times, 2 appears 2 times, and 3 appears 1 time, which are all unique, so the function should return true. Conversely, for the input {1, 2}, both 1 and 2 appear once, so the function should return false. Requirements: You must solve this problem using a HashMap to count the frequency of each value in a single pass, ensuring an efficient solution.


uniqueOccurrences([]) → true
uniqueOccurrences([1, 2, 2, 1, 1, 3]) → true
uniqueOccurrences([1, 2]) → false

...Save, Compile, Run (ctrl-enter)

public boolean uniqueOccurrences(int[] arr) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 310

Copyright Nick Parlante 2017 - privacy