Indeed interview question

Simple question about string and array but I did not give the optimal solution.