Yes you are right, your method is wrong for 456. I just do not see how the code you pasted can produce the behavior you describe, that's why either I get you wrong, or you interpret something differently than it really is.
What happens when you delete test case 1 and run only test case 2? For 456, valid answer is 6. Do you get locally answer 6 when you run your solution for n=456?
It kept outputting 1+6+4+5+6 = 16.
I don;t see how this can happen with your code and current tests. Is this exactly the output you get in logs?
Separated the assertions in diferent tests and added 100 random tests in Java.
I'd recommend you to read some particular paragraph in some very vague FAQ, but I won't ;)
Look at spaces around
2
.You might have been tripped up by the fact that there's no log for the first test (
16
) because you passed it. So this is mistaken:Test case is actually
456
. You'll see it if you print the input.and what about this?
...and why are you mixing the inputs of 2 different tests...????
Yes you are right, your method is wrong for 456. I just do not see how the code you pasted can produce the behavior you describe, that's why either I get you wrong, or you interpret something differently than it really is.
What happens when you delete test case 1 and run only test case 2? For 456, valid answer is 6. Do you get locally answer 6 when you run your solution for n=456?
I don;t see how this can happen with your code and current tests. Is this exactly the output you get in logs?
Your code works correctly for
16
also here on Codewars. It works wrong for456
.Maybe this could explain why you probably misread the logs.
Then, following the instructions there, post your code here, so we can check what's wrong.
Read this