You are viewing a single comment's thread. Return to all comments →
This is not an issue for the hackerrank case test but if I wanted to avoid adding the extra blank space after recursing through the tree, how would I do that?
There are many ways to do it. None of them result in pretty code. One way is to use a StringBuffer and save the output into the StringBuffer instead of printing the output immediatelly. Once the StringBuilder has the entire output, you can delete the last space and print the StringBuffer.