As reported: Twilio SDE L1 (2025), coding round (45 minutes, two questions), question 1: find duplicates in an array.
Given an integer array nums of length n where every value is in [1, n] and each value appears once or twice, return all the values that appear twice, in any order. Aim for O(n) time and constant extra space (the output does not count).
This is LeetCode 442 — Find All Duplicates in an Array.
Examples
[4,3,2,7,8,2,3,1] -> [2,3]
[1,1,2] -> [1]
[1] -> []
Constraints: 1 ≤ n ≤ 10^5; 1 ≤ nums[i] ≤ n; each value appears once or twice.
Code runner format: one JSON value per line (LeetCode's test-case format): nums. Implement findDuplicates(nums); the harness sorts your answer before printing.