This comment is hidden because it contains spoiler information about the solution
Okay I got it now so basically this problem tells (this was not explained in the description but according to the sample test cases) that there is a DMZ like north and south korea between left side and right side. I should've seen the pattern. Thank me later my fellow coders.
To anyone who is expert in C++ I would like to ask about my solution.
i finally achieved to pass it using this sintaxis:
std::string resultado = a + b;
But at the beggining, just using this other way it was failing in strange cases:
std::string resultado =input.substr(pos,pos+1);
I am having crazy troubles with C++ types in other katas and I don't know how to solve it, i have done some python and matlab before and I never faces this mindbreakers with types..
There is no problem with the tests, the error message is only showing the first failed test, look at the sample tests, the first one expects 3, the second 1, that's why you get that.
Your code is wrong, there should be more fixed tests (like the one your code didn't pass) to catch that.
writing in python, this test is going on:
Testing for [-15, 5, 11, 17, 19, -17, 20, -6, 17, -17, 19, 16, -15, -6, 20, 17]
and it returns to me:
It should work for random inputs too: -1 should equal 8
i did, also calculated myself, got the same result as my program, but test somehow thinks index 8 (17) is the right answer.. o.O
p.s. this aint only one failing like this
EDIT: i edited my program a bit, and it eventually passes, but on some occasions it would fail. passes like every 4th or 5th time. dunno what is going on, but nice work, that was interesting!
I failed a basic test (I passed 54/55 tests) but can't see what values were used as it seems to an 'extra basic test'. The random tests and the initial 10 basic tests give their test values. Any idea how to get this info? Thanks
Oh, I got it. While-loop is NOT slow, BUT my approach. Thank you.
It's not while loop that is slow, but the operations you do in it. (the ones you outlined in commented line, first post)
I didn't know the while statement is that slow. Thank you very much. Your answer is really helpful for me.
Not kata-related. And such approach is terribly slow, while the result can be trivially obtained in constant time.