Getting TLE in java

Hi, I am getting TLE response when I am trying to submit my solution in java. i am very much comfortable in java & using StringBuffer for this solution, but getting TLE.

Please help me in that case.

Hello @smrgrover2 actually i am c++ TA you.
if you want me to correct your code in c++ i can do please share your code.
you have raised the doubt here that means your course is in c++.
please share your code.
but if you want to get corrected your java code then you can raise the doubt again.
Happy Learning!!