upGrad interview question

DSA question on substrings and arrays