Ad
  • Custom User Avatar

    @IkIkleo @o2001

    The value should be an output integer, not an input, which is in string format. Therefore, the function should be able to operate with a string like "1 0000001 0000011 0000021 000003," for example. (Even my function cannot do that, but I found out thanks to this). However, if it is also meant as an input value (string), I won't unnecessarily complicate it.

  • Custom User Avatar

    NO! This solution is (n log n). Ideal is O(n).

  • Custom User Avatar
  • Custom User Avatar

    I'm not certain about other solutions, but in the mentioned solution by 'lklkleo,' I encountered (it seems) an error where, with higher values of controlled integers, there could be an attempt to convert a string to an integer without the possibility of a successful conversion (see the line: int start = std::stoi(str.substr(0, i));).

    If the compiler tried to convert, for example, the value "99999999999" using the stoi() function, it exceeds the maximum value of an 'int,' and the compiler should detect and terminate the program. Therefore, I believe either the server-side compiler does not treat this as an error, and it was fortunate that the results for tests with such large numbers were always the string 'str' (meaning the tests did not expose this error), or the tests are not comprehensive. Personally, I would lean toward the first possibility, but I'm not certain because I don't know the specifics of the written tests.

  • Custom User Avatar

    The error in your code lies in the possibility of attempting to convert an integer larger than its maximum possible value. Specifically, on this line: int start = std::stoi(str.substr(0, i));. I suspect that neither your code nor the server-side compiler addresses this issue, and due to improperly written tests, this error remains undetected.

  • Custom User Avatar

    You are mistaken because the correct output for this input is the same number, namely 78910111011, a single number, which fulfills the requirement. However, your solution causes a program crash, and the tests fail to capture this error.

  • Custom User Avatar

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

  • Custom User Avatar

    this solution is not entirely correct, it does not assign the correct value, for example, with the input '78910111012'. This solution even causes an error in Visual Studio

  • Custom User Avatar

    O(N*log N)!
    THIS IS ABSOLUTELY NOT A BEST PRACTICE!
    Clever? Maybe, but not best practice!

  • Custom User Avatar

    Clever (4,7s) but not best practice.... Sorry....(my code = 3,9s, but not clever :-( )

  • Custom User Avatar

    bad test for inputs...input -2 give -1 in this solution, not 0 (0 = right value)!