Mastercard Interview Question

DSA question on the string