24
2
Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order.
Your answer may be a snippet which assumes the input to be stored in a variable (d
, say) and evaluates to the correct result.
Test Cases
Each test case is a single line in the format input => output
. Note that other permutations of the output are valid as well.
[] => []
[-1, 0, 1] => []
[1, 1] => [1]
[3, 0, 0, 1, 1, 0, 5, 3] => [3, 0, 1]
[-34, 0, 1, -34, 4, 8, 4] => [-34, 4]
Order of the elements doesn't matter.
This is code golf, so the shortest answer (in bytes) wins.
4Related – Sp3000 – 2015-10-13T10:11:37.837
1since this is for array of integers code would be different. I think much shorter. That is for a string. – garg10may – 2015-10-13T10:21:01.480
1Are we allowed to accept input as lines instead of as an array? For example, instead of
[-1, 0, 1]
, can we input (replace \n with newlines):"-1\n0\n1"
? – Addison Crump – 2015-10-13T15:01:39.4131Does the output have to be a list or would a set be acceptable? – Dennis – 2015-10-13T15:06:12.190
And does it have to output in that format? – Addison Crump – 2015-10-13T15:06:59.623
Yes, the output needs to be an array, otherwise if iterable is allowed people would start producing
301
as results. – garg10may – 2015-10-14T01:59:47.760