Ad
  • Custom User Avatar

    Thank you very much for the hint. The downvoting is my misoperation in fact, sorry about it. Finnally fixed the issue haha.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Ah, thanks for explaining.

  • Custom User Avatar

    Asking for help and downvoting my comment at the same time...? Weirdest thing of the day, I bet...

    1. search for simpler ways. Find a way to "mutate a string" in java (yes, String are immutable. But that's an hint)
    2. there are no outputs of this length. If that happens with your code, you didn't understand the task correctly.

    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)

  • Custom User Avatar

    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.

  • Custom User Avatar

    Oh my gosh, it finally passed... .O.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    ok:

    • 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" ;)

  • Custom User Avatar

    There are dedicated tools/objects in Java for this type of stuff, just use them. ;)

  • Custom User Avatar

    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!