Write a function findDuplicates(numbers) that returns the duplicate numbers of an array: the numbers that occur more than once.
numbers is an array of integers. They can be positive, negative or 0.numbers. [1, 2, 3, 2, 1, 5] gives [1, 2], not [2, 1]. Do not sort the result.A set or a map helps you remember which numbers you have already seen.
findDuplicates([1, 2, 3, 2, 1, 5])Returns [ 1, 2 ]
findDuplicates([4, 4, 4])Returns [ 4 ]
findDuplicates([7, 8, 9])Returns []
Asked at Cognizant · Source
findDuplicates([ 1, 2, 3, 2, 1, 5 ])[ 1, 2 ]findDuplicates([ 5, 6, 5 ])[ 5 ]findDuplicates([ 7, 8, 9 ])[]Hidden tests run on Submit.