Pergunta de entrevista da empresa Booking.com

How do you remove duplicates from an array of integers?

Respostas da entrevista

Sigiloso

12 de ago. de 2014

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

2

Sigiloso

25 de mai. de 2015

hi

Sigiloso

25 de mai. de 2015

aliissa

Sigiloso

21 de set. de 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.

Sigiloso

6 de mai. de 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

Sigiloso

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

Sigiloso

6 de mai. de 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