Ad
  • Custom User Avatar

    No. It will of course depend on the details of the language/compiler/jit you are using, but for the most part in modern computing that kind of optimization is very premature -- the "slow" step is writing a string of ~n^2 characters. The pre-processing you are considering is in linear time, so it is insignificant as n grows large.

    Put simpler, if you have an input string of 100 characters, 5049 characters have to one-by-one added to your output string. With an input of 200 chars, you spend 2x as long splitting the string, true, but have to build an output of 20099 chars -- about 4x larger. This is true for every doubling of the input, and is going to be the real boundary for performance.

    For more on how SDE's think about performance of algorithms, look up "big O notation".

    All that said, to answer the question you actually asked, keeping input as a string is probably a trivial but (at small numbers) measurable gain in efficiency. But at work, my boss would care more about readibility in this case.

  • Custom User Avatar

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

  • Custom User Avatar

    The easiest way to find your old code is to go to your own profile and look at the solutions tab.

    You might (will?) have to be logged in to view your code.