You are viewing a single comment's thread. Return to all comments →
I would argue that's actually not a better solution. Ideally we'd return the string for another function to print out so decode() is reusable. It's not like hackerrank induces reusable coding styles... but hey we should try right?
But using StringBuilder increases space complexity.
Your code has space complexity O(N). Where N is length of string.
If you simply print it took O(1).
he said "reusability." if he's concerned with complexity then print.
do your work....
I agree with your point. Although using StringBuilder will increase the space complexity, but just printing out the result is meanless, that is to say, we can see the result string but we cannot access it because it technically does not exist.
Adding more to that, the real system will slow down for the more number of system input/output operation. It is better to use buffering mechanism to avoid unnecessary output which just slow down the system and have no use at all.