NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 1 | Analyse and Refactor Functions#167
NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 1 | Analyse and Refactor Functions#167ZabihollahNamazi wants to merge 10 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
For each function defined in the file, can you explain the complexity using Big O notation?
- Time Complexity -> for the original function
- Space Complexity: -> for the function you improved
- Optimal Time Complexity -> for the function you improved
| for value in values: | ||
| is_duplicate = False | ||
| for existing in unique_items: | ||
| if value == existing: | ||
| is_duplicate = True | ||
| break | ||
| if not is_duplicate: | ||
|
|
||
| if value not in seen: | ||
| seen.add(value) | ||
| unique_items.append(value) |
There was a problem hiding this comment.
Why not just convert the given list to a set (to remove duplicates) and then convert the set back to a list, like what you did in your JS implementation?
There was a problem hiding this comment.
I just wanted to try with something different rather than using same thing as I used in js
There was a problem hiding this comment.
Could you find out why the approach I mentioned won't work?
There was a problem hiding this comment.
TBH the one I wrote before and then one you mentioned they both work.
I run the test and it worked.
Thanks
There was a problem hiding this comment.
I brought this up because Set in Python does not preserve insertion order (JS's one does). The test script might be too simple to detect that.
There was a problem hiding this comment.
Ok I didn't know that tbh .
Thanks for explaining
|
All good. |
Self checklist
Optimized both the Python and JavaScript code by replacing slow codes with faster and better codes making lookups instant and cutting execution times on massive datasets