Making the cache private is a bizzare "extra challenge". I can't see how that provides any better functionality/encapsulation, if anything it just makes it harder to understand.
In this solution, only fibonacci(n) is stored in the memo. But since fibonacci(n - 1) and fibonacci(n - 2) are called, they can also be stored in the memo, so if the next test is fibonacci(n - 2) for example, the result will already be in the memo.
i believe performance is always the main concern; it isnt about looking cool and getting it in one line; that is clever yes but not best practice; best practice means most efficient and clear and scalable (which means if you want to add or remove a aspect of the code you dont have to rework on all aspects of the code only the aspect you want to) ALWAYS!!!!
it does not work with [5,0,0,0,0], [0,0,0,0,5] and [20,10,-80,10,10,15,35]
your result -1 -1 -1
should beat the result 0 4 0
because
Last one:
You are given the array {20,10,-80,10,10,15,35}
At index 0 the left side is {}
The right side is {10,-80,10,10,15,35}
They both are equal to 0 when added. (Empty arrays are equal to 0 in this problem)
Index 0 is the place where the left side and right side are equal.
I was wondering about this.. the problem describes this corner case but doesnt test for it when you submit? This code doesnt appear to handle that case.
You are storing the results in global scope, so any preceding function calls will cause the previously unnecessary values to accumulate.
Making the cache private is a bizzare "extra challenge". I can't see how that provides any better functionality/encapsulation, if anything it just makes it harder to understand.
The calls to fibonacci(n-1) and fibonacci(n-2) will store the value in memo, no reason to do this multiple times.
n is either fib(n-1) and fib(n-2)
In this solution, only fibonacci(n) is stored in the memo. But since fibonacci(n - 1) and fibonacci(n - 2) are called, they can also be stored in the memo, so if the next test is fibonacci(n - 2) for example, the result will already be in the memo.
which is exactly what is done here... Or are you talking about the base cases?
You should store the fibonacci(n - 1) in memo[n - 1] and the fibonacci(n - 2) in memo[n - 2]...
lol i tried this and didnt work
it does more than twice. 2n times
Nice :| Check my code. I use reduce once and a single loop without much variables
i believe performance is always the main concern; it isnt about looking cool and getting it in one line; that is clever yes but not best practice; best practice means most efficient and clear and scalable (which means if you want to add or remove a aspect of the code you dont have to rework on all aspects of the code only the aspect you want to) ALWAYS!!!!
This solution doesn't even pass all the tests.
it does not work with [5,0,0,0,0], [0,0,0,0,5] and [20,10,-80,10,10,15,35]
your result -1 -1 -1
should beat the result 0 4 0
because
Last one:
You are given the array {20,10,-80,10,10,15,35}
At index 0 the left side is {}
The right side is {10,-80,10,10,15,35}
They both are equal to 0 when added. (Empty arrays are equal to 0 in this problem)
Index 0 is the place where the left side and right side are equal.
What this simbol means matte?
O(n^2)
I was wondering about this.. the problem describes this corner case but doesnt test for it when you submit? This code doesnt appear to handle that case.
Loading more items...