- 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.
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.