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.
I was asked the same question in an interview and they were epecting me to solve in O(n). Rest all solutions are solving in O(n^2) but this one is of order O(n).
This solution is wrong. It will never return 0, which is the answer for an array such as [20,10,-80,10,10,15,35]
very clearly!
Congrats! This is the fastest solution among the top ones
https://jsperf.com/codewars-equal-sides-of-an-array
I'm trying to understand why still but good work!
The problem stated that the array would have at least one value; no need to check if (len === 0) for this problem.
Also, it's not clear, but it might be that any array of less than 3 values might need to return -1. (The tests seem to only use arrays of length 3 or more.)
Clear and understandable, I like this solution
this seems way too easy to be a 4kyu ...
The empty list is a valid subarray. Sum of empty list is 0, greater than any negative number. 0 is the correct answer when the array only has negative elements.
Why should you return 0 if it's all negative? Why shouldn't the solution compute it accordingly? 0 is the wrong answer if it's an all negative int array.
This should have a complexity of O(n)