Ad
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    In the description, the sentence "The initial string will contain at least two words, otherwise an empty string will be returned" is a bit confusing.
    "The initial string will contain at least two words" sounds like you make a statement about the types of string (testcases) that will be input in the function, so that you do not have to check for exceptions. This is somewhat clarified with the "otherwise" part, but an overall better phrasing might be:
    "If the initial string does not contain at least two words, an empty string will/should be returned".
    This special case also does not fit the other results this function returns. When balancing a string that has only one word, should you not just return that word itself instead of an empty string? Or the word follwed by a second, empty line? Might depend on the use case for this function, but at least that way, you would always return every word of the original string without deleting anything. If you did it this way, you could perhaps even omit the whole point, as it would be included in the last one:
    "In case of conflict or doubt, the first line will be the longest."

  • Custom User Avatar

    i had a very very very complex logic of almost 26 line of codes , to finally see that it's sthe cube of the input? wait give me a rope i'll be back :(

  • Custom User Avatar
  • Custom User Avatar

    Jajaja, no sé cómo no se me había ocurrido antes. Pero, mi código apesta jajaja.

  • Custom User Avatar

    Can someone please remove the troll solution from user MRGRD56 ? It might be correct, but just breaks display functionialty of the web site.

  • Custom User Avatar

    Oh man... I wish I'd spotted this earlier! My solution was a lot more convoluted spotting a pattern and connection between the supplied row number and the first number on the row rather than the simplest solution of "what is the answer in comparison to the row number"...

    Nice work!

  • Custom User Avatar

    I understand what do you mean. I am not presenting well. I agree that it is the best way for the computer to run.
    I just want to say that not all know this method. It also require your math skill.
    Not everyone has good math skill, but this method is the most fast way and clever.

  • Custom User Avatar

    I'm going to have to completely disagree with you banny127: this is the best answer because it was calculated before coding.

    Math first; code later. Your CPU will thank you.

    Programmers need to have a ton of tools in their toolbox, and your casual dismissal of "algebra" is, frankly, terrifying--given that all programming boils down to logical/mathematical computations.

  • Custom User Avatar

    That depends on the view of what is the best solution. However, in most computer algorithms the best solution (out of all that give correct results) the best is where is minimum used memory & CPU time. This is a solution in constant time because there was a previous analysis with pen & paper. That is what I call a real optimization - the author found a way of different solving of the same problem using less resources.

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    That's a great idea, thanks! I've added in a couple of new tests for both 0's and negative numbers.

  • Custom User Avatar

    You could also include negative numbers in your test cases, because you even mention that there could be any number.

    The string passed into your function will only contain numbers in string format and can contain any number of comma seperated integers.
  • Loading more items...