Created
August 20, 2020 20:52
-
-
Save MichaelSDavid/8da8040bbdd40d81dbba595aa89e743b to your computer and use it in GitHub Desktop.
Daily Interview Pro example solution for shifted string problem on 08/20/2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_shifted(a, b): | |
shift_list = [] | |
def shift(n, s): | |
tmp = [char for char in s] | |
shift_str = ''.join(tmp[-n:] + tmp[:-n]) | |
return shift_str | |
for i in range(1, len(a)): | |
shift_list.append(shift(i, a)) | |
if b in shift_list: | |
return True | |
else: | |
return False | |
print(is_shifted('abcde', 'cdeab')) # True | |
print(is_shifted('abc', 'acb')) # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment