Find All Duplicates in an Array Problem

Find All Duplicates in an Array Problem — ExecCode Medium DSA Practice

Solve the Find All Duplicates in an Array problem on ExecCode. Free online medium DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an integer array nums of length n where every value is in the range [1, n] and each value appears once or twice, return every value that appears exactly twice, without using any extra space beyond the output list.

Examples

Input nums = [4, 3, 2, 7, 8, 2, 3, 1]; Output [3, 2]. Input nums = [1, 1, 2]; Output [1]. Input nums = [1]; Output []

Constraints

n == nums.length 1 <= n <= 10^5 1 <= nums[i] <= n Each value appears once or twice.

Practice Find All Duplicates in an Array free on ExecCode. Browse DSA problems, topic map, and placement guides.