The problem. You are given an integer array nums of length n where every value is in the range 1 to n, and each value appears once or twice. Return every value that appears twice. The follow-up asks for O(n) time and O(1) extra space.
Input: nums = [4, 3, 2, 7, 8, 2, 3, 1]
Output: [2, 3]
Input: nums = [1, 1, 2]
Output: [1]
Input: nums = [1]
Output: []The answer can be returned in any order. Keep an eye on the unusual promise — values from 1 to n in an array of length n. The best solution depends on it completely.
Free account
Sign up to read the rest of this lesson: 5 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come