Reputation: 15
following will be the input on STDIN.
The first line contains an integer, n, denoting the size of the numbers array.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer describing the value of numbers[i].
I want to print the integer denoting the number of non-unique values in numbers to STDOUT.
Sample Input
8 1 3 1 4 5 6 3 2
Sample Output
2
Upvotes: 0
Views: 180
Reputation: 1700
Try using array_unique()
and count()
functions:
$array = [];
while ($in = fread(STDIN, 1024)) {
$array = array_merge($array, explode("\n", $in));
}
array_shift($array);
echo (count($array) - count(array_unique($array)));
Upvotes: 1