Subex interview question

Writing Algorithm for Substring and behaviour of the same in different angles. Covered the Number of Instruction set and also the Loop in the logic