Test cases not passed

Is it because of the space complexity?
if yes, how do I clear the char arrays?

Hey @shubhamhalder0 no your code runs fine. You just need to print the answer for every testcase in a new line, so please use cout<<endl ,every time your k is decremented.
If you don’t have any further queries please mark the doubt as resolved