Problem · Array
Find Doubles
Learn this problemProblem statement
Given a list of N integers, not necessarily unique, find all elements of the list for which there exists exactly one element of the list which is twice that number. The integers range from 0 to 1000. The list has no more than 100,000 elements.
Your code should find the appropriate values and print them to STDOUT in sorted order.
Function
findDoubles(numbers: List<Integer>) → List<Integer>Examples
Example 1
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 8]return = [0, 1, 2, 3]
8 is 4*2, but 8 is present twice, 0 is its own double, so it's part of the result.
Example 2
numbers = [7, 17, 11, 1, 23]return = []Nothing is exactly twice another element.
Example 3
numbers = [1, 1, 2]return = [1, 1]
1 and 1 both have their double 2 present, and 2 is present in the list only once.