## Or Shachar

BAN USERimport re

def right_match(a,b):

""" checks if any character of a is in b right edge """

# True in empty way

if len(a) == 0 : return True

# can never be true

if len(a) > len(b) : return False

try:

index = a.index(b[-1])

except:

return False;

return right_match(a[:index]+a[index+1:],b[0:-1])

def left_match(a,b):

""" checks if any character of a is in b left edge """

# True in empty way

if len(a) == 0 : return True

# can never be true

if len(a) > len(b) : return False

try:

index = a.index(b[0])

except:

return False

return left_match(a[:index]+a[index+1:],b[1:0])

def has_anagram_substring(a,b):

""" finds if anagram of a contains in b """

# True in empty way

if len(a) == 0 : return True

# can never be true

if len(a) > len(b) : return False

# step one - find all occurances of a[0]

# assuming a is alphanumeric character

occurances = [m.start() for m in re.finditer(a[0:1],b)]

# if that wasn't found then false for sure

if len(occurances) == 0 : return False

for index in occurances:

for i in range(len(a)):

if right_match(a[1:1+i],b[:index]) and left_match(a[1+i:],b[index+1:]) : return True

return False

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Heres my implementation in python. a bit code repetition but it works:

- Or Shachar September 18, 2016