Pergunta de entrevista da empresa Booking.com

Can you optimize the algoritm which you wrote.

Respostas da entrevista

Sigiloso

19 de set. de 2014

With hash table is fastest

Sigiloso

6 de out. de 2014

sub anagram_part { my ( $str, $substr ) = @_; my @str = split //, $str; my @substr = split //, $substr; L: while ( @str && @substr ) { my $cl = shift @substr; while ( my $c = shift @str ) { goto L if $cl eq $c; } return 0; } return 0 if scalar @substr; return 1; }

Sigiloso

13 de jan. de 2015

public static boolean check(String original, String subString) { if(original == null || subString == null) { return false; } if("".equals(subString)) { return true; } int positionAtOriginal = 0; for(int i = 0; i < subString.length(); i++) { char currentChar = subString.charAt(i); boolean findCurrentChar = false; while(positionAtOriginal < original.length()) { if(original.charAt(positionAtOriginal) == currentChar) { findCurrentChar = true; } positionAtOriginal++; if(findCurrentChar) { break; } } if(!findCurrentChar) { return false; } } return true; }

Sigiloso

1 de fev. de 2015

# python def doit(s, subs): h = {} for c in s: if c in h: h[c] += 1 else: h[c] = 1 for c in subs: if c not in h or h[c] == 0: return False h[c] -= 1 return True

Sigiloso

28 de dez. de 2015

# Python def is_partial_anagram(word, partial): return set(partial).issubset(set(word))