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.
Yes reduce will be run n times. And each operation in reduce will cost a max of O(log n) time. Therefore second line takes O(n * log n) time.
Please note that dictionary/map insertions take O(log n) time for each insert operation. I advise you read my last post again carefully.
PS: Your calculations would make my solution linear O(n)+O(n)+O(n) = O(n). I'm claiming that mine is not linear but, O(nlogn) and the original solution on this post is quadratic i.e. O(n^2).
This will unnecessarily perform all arithmetic operations for each call. 4 operations when you only need to perform 1. So wasteful!
The formula is not accurate for n > 71. Hence, this solution won't work for even trivial values.
Substandard solution
You iterate n times again with reduce to insert it into an object literal, how does it make logn?? it seems it is O(n) -- O(n)+O(n)+O(n)
This could be greatly simplified.
Therefore, no need to check if a and c are 1 or not. Third condition should just be (a === 1 || c === 1 || b === 1).
This comment is hidden because it contains spoiler information about the solution
May you explain why it is O(nlogn), not very experienced about big o notation
This is such a bad solution! This solves it in quadratic time when it can be accomplished in O(nlogn). See my solution as an alternative.
Seems clean but, I wonder how to do error handling (Unrecognised operation, type checking values and division by 0) in this cleanly too!
Exactly! This method seems clean but it is unnecessarily computing all the operations every time basicOp is called.