Barclays interview question

Medium-Hard DSA question on string manipulation and pattern detections