Glasgow | 25-SDC-Nov | Nataliia Volkova | Sprint 1 | Big-O notation and refactoring in Python tasks#96
Glasgow | 25-SDC-Nov | Nataliia Volkova | Sprint 1 | Big-O notation and refactoring in Python tasks#96Nataliia74 wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Can you revert the changes made in the Sprint-1/JavaScript folder to keep the branch clean?
| Space Complexity: | ||
| Optimal time complexity: | ||
| Time Complexity: O(n+m) | ||
| Space Complexity: O(m+k) |
There was a problem hiding this comment.
Hello CJ Yuan, fixed experimental mistake.
| set_1 = set(first_sequence) | ||
| set_2 = [] | ||
|
|
||
| for seq in set_1: | ||
| if seq in second_sequence: | ||
| set_2.append(seq) | ||
| return set_2 |
There was a problem hiding this comment.
Yes, my bad. I changed it a little bit.
| differ = target_sum - num | ||
| if differ in set_1: | ||
| return True | ||
| result.append(differ) |
| for num in numbers: | ||
| differ = target_sum - num | ||
| if differ in set_1: | ||
| return True |
There was a problem hiding this comment.
This implementation is slightly different from the original implementation.
The original implementation does not allow the same element to be paired with itself. That is,
assert has_pair_with_sum([1, 4], 2) is expected to return False, but your implementation returns True.
|
The validation bot is expecting one PR for the complexity module. |
Learners, PR Template
Self checklist
To solve these tasks I used again a hash set for constant-time lookups and processes each element once, but unlike JS logic new Set a Python set does not keep ordering, so I utilized OrderedDict.fromkeys() to create an ordered list of keys with unique items.