BackmediumArrays Salesforce

NEW OR EXISTING ID 2 Solution

Problem Statement

Given an array of integers, return a list of IDs that already exist in the array more than once.

Example 1
Input
[1, 2, 3, 2, 4, 5, 2]
Output
[2]

Explanation: Step-by-step: We initialize an empty list to store duplicate IDs. We iterate through the input array. For each number, we check if it exists in the array more than once by counting its occurrences. If it does, we add it to our list of duplicate IDs. Finally, we return the list of duplicate IDs.

Example 2
Input
[1, 1, 2, 2, 3, 3, 4, 4]
Output
[1, 2, 3, 4]

Explanation: Step-by-step: We initialize an empty list to store duplicate IDs. We iterate through the input array. For each number, we check if it exists in the array more than once by counting its occurrences. If it does, we add it to our list of duplicate IDs. Finally, we return the list of duplicate IDs.

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