Texas Instruments Interview Question

How to detect 101 in a string and repeat it in the output?