Booking.com Interview Question

How do you remove duplicates from an array of integers?

Interview Answers

Anonymous

Aug 12, 2014

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

2

Anonymous

May 25, 2015

hi

Anonymous

May 25, 2015

aliissa

Anonymous

Sep 21, 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.

Anonymous

May 6, 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

Anonymous

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

Anonymous

May 6, 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