Sollicitatievraag bij Booking.com

How do you remove duplicates from an array of integers?

Antwoorden op sollicitatievragen

Anoniem

12 aug 2014

my @input = (1,2,3,1,10,4,3,4,5,2,3,4); my $seen = {} my @result = grep { not $seen->{$_} } @input;

2

Anoniem

25 mei 2015

hi

Anoniem

25 mei 2015

aliissa

Anoniem

21 sep 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.

Anoniem

6 mei 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

Anoniem

25 jul 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); }

Anoniem

6 mei 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

1