Mastercard interview question

DSA question on the string