Loading...
Engaged Employer
Can you optimize the algoritm which you wrote.
Anonymous
With hash table is fastest
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; }
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; }
# 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
# Python def is_partial_anagram(word, partial): return set(partial).issubset(set(word))
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.