Nagesh Knitwears interview question

Code on string and array