BudiBadu Logo
00:00

Duplicate Indices Map

Array Easy 4 views

You are processing a batch of records represented by integers. Some records appear more than once, and the review team needs a quick way to spot where each repeated record occurs. Your task is to build a collection of index groups: for every value that appears at least twice, create a list of its indices in ascending order. Values that appear only once should be skipped. The final result is a list of these index lists, ordered by the first appearance of each duplicated value.

Imagine placing bookmarks in a ledger. Whenever a page number repeats, you slide each bookmark into the ledger so reviewers can jump directly to the duplicates. Once you finish browsing the ledger, you hand the bookmarks over grouped by page number. If no value repeats, you return an empty list.

This problem emphasizes mapping and grouping while preserving original order. Negative numbers are allowed and follow the same rule. The structure of the output should let analysts immediately see which values need attention and where they appear within the array.

Example 1:

Input: nums = [1,2,3,1,2,1]
Output: [[0,3,5],[1,4]]
Explanation: Value 1 appears at indices 0, 3, 5; value 2 appears at indices 1, 4.

Example 2:

Input: nums = [4,5,6]
Output: []
Explanation: No duplicates exist.

Example 3:

Input: nums = [7,7,7]
Output: [[0,1,2]]
Explanation: Value 7 repeats across all positions.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Duplicate Indices Map

Array Easy 4 views

You are processing a batch of records represented by integers. Some records appear more than once, and the review team needs a quick way to spot where each repeated record occurs. Your task is to build a collection of index groups: for every value that appears at least twice, create a list of its indices in ascending order. Values that appear only once should be skipped. The final result is a list of these index lists, ordered by the first appearance of each duplicated value.

Imagine placing bookmarks in a ledger. Whenever a page number repeats, you slide each bookmark into the ledger so reviewers can jump directly to the duplicates. Once you finish browsing the ledger, you hand the bookmarks over grouped by page number. If no value repeats, you return an empty list.

This problem emphasizes mapping and grouping while preserving original order. Negative numbers are allowed and follow the same rule. The structure of the output should let analysts immediately see which values need attention and where they appear within the array.

Example 1:

Input: nums = [1,2,3,1,2,1]
Output: [[0,3,5],[1,4]]
Explanation: Value 1 appears at indices 0, 3, 5; value 2 appears at indices 1, 4.

Example 2:

Input: nums = [4,5,6]
Output: []
Explanation: No duplicates exist.

Example 3:

Input: nums = [7,7,7]
Output: [[0,1,2]]
Explanation: Value 7 repeats across all positions.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.