How do you remove duplicates from an array of integers?
Risposte di colloquio
Anonimo
12 ago 2014
my @input = (1,2,3,1,10,4,3,4,5,2,3,4);
my $seen = {}
my @result = grep { not $seen->{$_} } @input;
2
Anonimo
25 mag 2015
hi
Anonimo
25 mag 2015
aliissa
Anonimo
21 set 2012
Upon giving a not very efficient answer, the interviewer will ask if you know a more efficient way to solve the problem. You can use any data-strcture so throwing the array in a hash-map will do.
Anonimo
6 mag 2013
Answer in Java, with example:
Integer[] input = new Integer[] {3, 3, 2, 1, 2, 45, 32, 1, 23, 4};
Gingleton g = Gingleton.getInstance(); print(input); Set
uniques = new LinkedHashSet(); for(int i=0; i
Anonimo
25 lug 2014
use strict;
use warnings;
my @input = (1,2,3,1,10,4,3,4,5,2,3,4);
my $input = {};
foreach (@input) {
if (exists $input->{$_}) {
$_ = undef;
} else {
$input->{$_} = undef;
}
}
foreach (@input) {
print "$_ ", if (defined);
}
Anonimo
6 mag 2013
Answer in Java, with example:
Integer[] input = new Integer[] {3, 3, 2, 1, 2, 45, 32, 1, 23, 4};
Set uniques = new LinkedHashSet();
for(int i=0; i