Recent Oracle Interview question - Oracle Tech Screen - String manipulation - Need better solution

I was recently asked the below question in the Oracle Tech screen. I was able to solve it via String split function but the interviewer mentioned to change my approach and use collections which I was not able to come up with. The language used was java.

What would be a better collection/data structure way to solve the below problem:

Use case 1
Input - 2[bcbc]
Output - bcbcbcbc

Use case 2
Input - 3[a2[bdbd]]
Output - abdbdbdbdabdbdbdbdabdbdbdbd

Comments (6)