Skip to main content
CodeOath
← All problems

Problem

Count Duplicate Array Members

Medium
  • arrays
  • hash-table

Return an object that maps each value appearing more than once in arr to the number of times it appears. Values that appear only once are left out.

Example 1
Input
arr = [1, 2, 2, 3, 3, 3, 4]
Output
{ 2: 2, 3: 3 }
Explanation

2 appears twice and 3 appears three times. 1 and 4 appear once.

Example 2
Input
arr = [5, 5, 5, 5]
Output
{ 5: 4 }
Explanation

a single value can be the whole result.

Example 3
Input
arr = ["a", "b", "a", "c", "b", "b"]
Output
{ a: 2, b: 3 }
Explanation

the values can be text as well. "c" appears once, so it is left out.

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.