Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
@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.
NO! This solution is (n log n). Ideal is O(n).
Np ;-)
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.
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.
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.
This comment is hidden because it contains spoiler information about the solution
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
O(N*log N)!
THIS IS ABSOLUTELY NOT A BEST PRACTICE!
Clever? Maybe, but not best practice!
Clever (4,7s) but not best practice.... Sorry....(my code = 3,9s, but not clever :-( )
bad test for inputs...input -2 give -1 in this solution, not 0 (0 = right value)!