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.
Don't bother to answer to this unless you wan't to help others having similar issue, because I already managed to submit a suitable solution.
This comment is hidden because it contains spoiler information about the solution
Hi,
Thanks for the comprehensive explanation and answer. I already managed to complete this Kata using a different approach to the problem.
Hi Samuq
There are quite a few optimizations you can do here. Lets for arguments sake say that
str2
is of length1000
andstr1
length100
. This is very conservative numbers because the strings I use in this kata are huge. So for our example, we can see that:1.)
every
isO(n)
. This means if we have no code to run inside the callback, it will execute1000
times. But we do have code in there, so lets go deeper.2.) So inside
every
, you are doingindexOf
. This operation is alsoO(n)
. This means if we had didindexOf
only once, it will iterate over everychar
instr1
. This will be100
times.3.)
splice
is anotherO(n)
operation. Withsplice
, it will remove an element and then re-index the entire array. In order to do this, it needs to run over all the elements in the array. In this case, it will be100
times.So conservatively, we are looking at
1000 x 100 + 1000 x 100
operations for smallstr1
andstr2
. You can see how this can blow up.I have the same problem..
This comment is hidden because it contains spoiler information about the solution
I have the same issue. I wonder how can I optimize more..