Hi everyone.
Need help to solve this code.
Thanks in advance.
For small strings, you could just try out all available rotations. You might anyway want to check length first.
For larger strings I would probably assemble a set of positions for each letter in the two words, so "mississippi"
for example would look like {'m':[0], 'i':[1, 4, 7, 10], 's':[2, 3, 5, 6], 'p':[8, 9]}
, check that counts matched then make a set of possible mappings between each letter in turn, intersecting the offsets, which would either result in an empty set (no possible rotation) or a set of valid rotation values (for example "abbabbabbabb"
has four possible rotations to "babbabbabbab"
).