Booking.com Interview Question

Can you optimize the algoritm which you wrote.

Interview Answers

Anonymous

Sep 19, 2014

With hash table is fastest

Anonymous

Jan 13, 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; }

Anonymous

Feb 1, 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

Anonymous

Dec 28, 2015

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

Anonymous

Oct 6, 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; }