The problem is borrowed from InterviewCake. Although they did a great job explaining the solution in detail, there aren’t that many visuals. This post is my attempt to visualize the solution: Sample I/O Input: ‘cat’ output: {‘cat’, ‘atc’, ‘act’, ‘tca’, ‘tac’, ‘cta’} The Pattern: Let’s start small. With 2 chars only. Suppose we had…