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.
@snake2
Assume that there is no match for the midpoint, so you'd return -1.
arr.each_index do |i|
will iterate n times (where n is the length ofarr
).Inside each iteration, the
reduce
call is itself iterating m times (0...i
) and l times (i+1..-1
) [l + m = n - 1, though, which is effectively n].So you are doing n times n (or n2) iterations, so you have a function that costs O(n2) to run.
This can be solved with a cost of O(n). Someone smarter than me might have one even better. Maybe.
what makes it not eff? also what of my code? its a little similar, but im just a beginner.