Skip to main content
CodeOath
← All problems

Problem

Find Duplicate Array Positions

Medium
  • arrays
  • hash-table

Return an object that maps each value appearing more than once in arr to the positions where it appears. Positions are zero-based and listed in increasing order. Values that appear only once are left out.

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

2 sits at positions 1 and 2, and 3 at positions 3, 4 and 5.

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

one value fills every position.

Example 3
Input
arr = ["a", "b", "a", "c", "b", "b"]
Output
{ a: [0, 2], b: [1, 4, 5] }
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.