- Identify areas of inefficiency that contribute to higher time or space complexity
- Refactor the code to reduce its complexity.
There are some common programming tasks in this folder. The same tasks are provided in both JavaScript and Python. You should solve each task in one language. We recommend you pick some tasks in each language.
- Identify the section(s) of code that contribute to the complexity of the code.
- Explain the complexity using Big O notation.
- Identify whether the complexity can be reduced. If so, refactor the code to reduce its complexity. If you don't think the complexity can be reduced, explain why not in a comment.
- Provide the refactored code and briefly set out the complexity of your refactor.
- Open a PR with your changes, explaining what you have done and why. Include any resources you used to complete your work.
- Now go and find another PR from a colleague.
- Review this PR. Do you agree with their analysis? What about their solution or solutions? Is there a more efficient strategy you could share with your colleague to improve the code. If so, how can you show clearly and respectfully that your strategy is more efficient?
You can review as many PRs as you like. You must respond to the reviews you receive. You can use class time to complete this project.
First, create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateThen install dependencies:
pip install -r requirements.txtRun tests:
# Run all tests once
pytest -v
# Run all tests in watch mode (auto-rerun on file changes)
pytest -v --watchNavigate to the JavaScript directory first.
# Run all tests once
npm run test
# Run all tests in watch mode (auto-rerun on file changes)
npm run test:watch- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted
- https://www.w3schools.com/python/ref_set_intersection.asp
- https://www.w3schools.com/python/ref_func_sorted.asp
- https://www.hellointerview.com/learn/code/two-pointers/overview
- https://www.youtube.com/watch?v=syTs9_w-pwA
Tip
Big-O notation focuses on the dominant trend of how resource usage grows as the input size n gets very large. It simplifies things by ignoring constant factors (multipliers) and lower-order terms.
For example, an algorithm that takes 2n steps and another that takes n steps are both considered O(n) (Linear Time). Why? Because as n gets huge, both grow directly in proportion to n. The factor of 2 doesn't change the fundamental linear growth pattern.
Similarly, if you have two separate loops, each running n times (total 2n steps), the complexity is still O(n). This is different from nested loops, where one loop runs n times inside another loop that also runs n times, leading to n * n or O(n²) complexity.