Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
The complexity analysis on the JS implementation looks good.
There was a problem hiding this comment.
The complexity of this Python implementation is not O(nm).
There was a problem hiding this comment.
thanks, time complexity will be O(nnm) so i change the code with AI help which is a bit hard for me to understand. So Time complexity: O(n+m), am i right?
There was a problem hiding this comment.
The complexity of the original implementation is more like O( nm * min(m, n) ), or loosely
Yes, your refactored implementation is
| // For two loops, we have visit each element of array in order to get the result | ||
| // so time complexity is O (n) which means linear. | ||
| // Regarding space complexity, we only get one result | ||
| // for sum and product no matter how long the array is.so it is O(1)(constant) | ||
| // While time complexity is O(n), optimal time complexity should be O(n) because loop | ||
| // has to go each single element in array. |
There was a problem hiding this comment.
Note: While the complexity remains
There was a problem hiding this comment.
Thanks, i put one loop now which make a bit faster with updated comment
|
All good. Well done. |
Self checklist
Task code
CYF-1173
Changelist
did prep and get general idea about JavaScript and Python. Also learn from test and give explanation about refactor.