Tap here to switch tabs
Problem
Ask
Submissions

Problem: Find All Duplicates in an Array

med
30 min
Explore how to find all numbers that occur twice in an array where each integer appears once or twice. Learn to design an algorithm running in linear time and constant space, essential for efficient problem-solving in coding interviews.

Statement

Given an integer array, nums, of length nn, where all the integers of nums are in the range [1,n][1, n] and each integer appears once or twice, return an array of all the integers that appear twice.

Note: Write an algorithm that runs in O(n)O(n) time and uses only constant auxiliary space, excluding the space occupied by the output.

Constraints:

  • n=n = nums.length

  • 1n1031 \leq n \leq 10^3

  • 11 \leq nums[i] n\leq n

  • Each element in nums appears once or twice.

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Find All Duplicates in an Array

med
30 min
Explore how to find all numbers that occur twice in an array where each integer appears once or twice. Learn to design an algorithm running in linear time and constant space, essential for efficient problem-solving in coding interviews.

Statement

Given an integer array, nums, of length nn, where all the integers of nums are in the range [1,n][1, n] and each integer appears once or twice, return an array of all the integers that appear twice.

Note: Write an algorithm that runs in O(n)O(n) time and uses only constant auxiliary space, excluding the space occupied by the output.

Constraints:

  • n=n = nums.length

  • 1n1031 \leq n \leq 10^3

  • 11 \leq nums[i] n\leq n

  • Each element in nums appears once or twice.