In the Python solution, I keep getting a timeout, saying my code takes over 12 seconds to complete.
Now, my code may not be optimal, but on my run-of-the-mill desktop machine, even the code sample at https://pastebin.com/SaU5Jfcv (mentioned in the comment from Naiten) completes in under a second.
Thanks a lot for your reply and help. I googled a lot and cannot find a way to build such a huge string in memory to return. I tried ByteArrayInputStream and FileInputStream and FileOutputStream. Could you please give me a hint on what class or api I could use to solve the issue? Thank you very much.
do not concatenate strings. Considering the size of some output, it's a bad idea. That'll help a bit (but not enough)
the way you generate the indentations might cause some troubles too (create an array, create a string, iterate the whole string replacing the characters, lots of work on this side)
you can try to handle the purifier directly in your loop (on the fly) rather than in your while loop if hte above is still not enough (not sure that's really slowing your code, as you said before, but just in case)
EDIT: yep, correcting these stuff, your solution passes the tests. Think about "fundamentals" ;)
In performace test, there is a test input string which length is 18 000 000. and the output string's length is 164 000 000. In java, trying to build a string with a length of 164 000 000 will cause out of memory since the return type of test method is string. Thanks for any advice to pass the test? Thank you!
Thank you very much for the hint. The downvoting is my misoperation in fact, sorry about it. Finnally fixed the issue haha.
In the Python solution, I keep getting a timeout, saying my code takes over 12 seconds to complete.
Now, my code may not be optimal, but on my run-of-the-mill desktop machine, even the code sample at https://pastebin.com/SaU5Jfcv (mentioned in the comment from Naiten) completes in under a second.
Ah, thanks for explaining.
Asking for help and downvoting my comment at the same time...? Weirdest thing of the day, I bet...
It's 2 kyu, I won't give you the answer straight away (especially considering that it's a really basic knowledge that you seem to be missing)
Thanks a lot for your reply and help. I googled a lot and cannot find a way to build such a huge string in memory to return. I tried ByteArrayInputStream and FileInputStream and FileOutputStream. Could you please give me a hint on what class or api I could use to solve the issue? Thank you very much.
Oh my gosh, it finally passed... .O.
This comment is hidden because it contains spoiler information about the solution
ok:
EDIT: yep, correcting these stuff, your solution passes the tests. Think about "fundamentals" ;)
There are dedicated tools/objects in Java for this type of stuff, just use them. ;)
In performace test, there is a test input string which length is 18 000 000. and the output string's length is 164 000 000. In java, trying to build a string with a length of 164 000 000 will cause out of memory since the return type of test method is string. Thanks for any advice to pass the test? Thank you!