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.
You also have O(n), if you want to find solutions with the best result, then there are other sites for this, where this is emphasized. Or you can post 2 solutions. One is short, the other is optimal.
For all arrays of type [0,0,0,1] you have the same result.
I don't think you'll get extra points for fast execution here.
SENSENEL, this is a very good question. Unfortunately, it is a brute force solution that is not optimal. See my solution which is 8 character longer (when removing spaces that were added for readability) but has an optimal O(n) time and O(n) space complexity.
I created a bechmark with a simple case, 1000 elements array, with no matching numbers (to test the worst-case scenerio of searching everything, instead of relying on luck to find the mathing numbers in first iterations). It compares my solution, Niksonman's solution and your solution: jsbench.me/23l4lcraig/1 - try changing the 1000 to million and see what happens.
@SENSENEL, you asked a very good question. In real recruitment tasks, the tests are more complex than here and also check the time and space complexity, so it is important to always keep it in mind. For example try how all of those solutions would pass the tests on AlgoExpert, which has exactly this task as its first task in their Easy list.
It seems to me that you have made an assumption that we know what you are talking about, but I should point out that's not the case. What exactly you want?
:D
Yeah, generating that output is overdoing it mightily. That must have been quite a lot of work!
You're welcome. ^^
Yes. It's that simple.
I always thought warnings like "do not include the quotes" were superfluous. :/
You are returning
'=> 15 (buy at 1, 2, 3, 4, 5 and then sell all at 6)'
.YOU MUST RETURN A NUMBER.
You are not returning a string, are you? You have to return a number.
What is the complete, exact text of the failure message?
yes. @rowcased is correct.
'.... .... . ..... .... ... .... .... '
'.... .... . ..... .... ... .... ....'
it's hard to see, but yours have a trailing whitespace
The numbers of interest are all the number between 0 and
n
which squared contain at least one digitd
. Is it clearer now? And no, they're not passed to you in any way, you have to get them for yourself.This comment is hidden because it contains spoiler information about the solution
Just a year at codewars and nothing else.)) 1-2 cata per day