BackeasyArrays arrays easy

Distinct Element Occurrences Solution

Problem Statement

You are given an array of integers. Output an object containing the count of each distinct element and their minimum indices.

Example 1
Input
[1, 2, 2, 1, 1, 3]
Output
{"1": [0, 2, 5], "2": [1, 3], "3": [4]}

Explanation: The count of 1 is 4, appearing at indices [0, 2, 5]. The count of 2 is 2, appearing at indices [1, 3]. The count of 3 is 1, appearing at index [4].

Constraints

  • Input array will contain only unique integers.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free