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.
That is ok, pfela.
"Best" is a relative word and your solution seems to have better performance.
I just thoght in a simple solution, but you are right. I am using array_slice to retrieve something I could put in a cache and improve performance.
Sorry but this is not best practices. Sure it looks pretty with it being only a few lines of code but it's O(n^2) whereas my solution is O(n).
Let n = 10000;
Runtime for this solution ~= 0.0433 seconds
Runtime for my solution ~= 0.0017 seconds
Let n = 100000;
Runtime for this solution ~= 4.8142 seconds
Runtime for my solution ~= 0.0169 seconds
Let n = 1000000;
Runtime for this solution == Fails (out of memory after running locally for over 15 minutes)
Runtime for my solution ~= 0.1612 seconds
super clever! but looking you code I have to point out that with
return array_slice($signature, 0, $n);
you dont have to subtrac -3 at the for loop , array slice will cut those extra 3 opperation for youReally a clever solution! :)
well done bro