The approach.
The explanation.
The code.
Make technical answers easier to follow with structured explanations and formatted code suggestions, streamed as they’re generated.
function findDuplicates(values) { const seen = new Set(); const duplicates = new Set(); for (const value of values) { if (seen.has(value)) { duplicates.add(value); } seen.add(value); } return [...duplicates];}Talk through the trade-off. A set remembers what you’ve seen. Explain the extra memory, too.