my answer is essentially the same as the ans approach in JAVA and it is giving TLE …
Please see
My answer is essentially the same as the ans approach in JAVA and it is giving TL
@Anubhav Please checkout the Implementation details ( Java section ) slide on http://www.interviewbit.com/courses/programming/topics/strings/
In general, if you want mutable string, use StringBuffer / StringBuilder. Doing N appends of size 1 to String S, is of O(N^2). Howver, appending to StringBuilder and then finally converting to string is O(N).