Ad
  • Custom User Avatar

    To enhance fastness, it would be better to convert the String to StringBuilder, do the replaces like we did with String, and then convert the SB back to String. But it would still remain in O(n), thus it may not be worth the effort, but is nice to know.

  • Custom User Avatar

    Both solutions are in the same complexity class O(n). So it's not really a win to use a for loop, instead of just replacing several times. Your code has also a bad readability, and is therefore less maintainable in production.

    Our method will not be slow like you say, only somewhat slower than yours --> See big O notation: https://en.wikipedia.org/wiki/Big_O_notation

  • Custom User Avatar

    Yes, your solution is shorter. But I think that we (developers) should write faster code. Imagine that your method will execute 1_000_000 times in production every 1 minute. It will be slow.

    Also I think that this kata we can't solve with regex, because we have several replace templates.

    Sorry for bad English.

  • Custom User Avatar

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

  • Custom User Avatar

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