Guides
Setup — Environment & Tools
Mark when done:
Environment Setup
Python
# Verify Python 3.8+
python --version
# No external packages needed -- everything uses the standard library
Recommended Editor
- VS Code with Python extension (free, best for LeetCode-style work)
- Install the "Python" extension by Microsoft
Project Structure
Each solution file is standalone. To run and test:
cd phase-1-foundation/01-arrays-strings/solutions
python 01-two-sum.py
Every .py file includes test cases at the bottom. Run the file directly to verify.
LeetCode Tips
- Test locally first -- every
.pyfile has test cases you can run - Then submit on LeetCode -- link is in each file header
- Time yourself -- Easy: 15 min, Medium: 25 min, Hard: 40 min
- If you exceed time limit: stop, read hints in the file, try again
Useful Python Imports for DSA
from collections import defaultdict, Counter, deque, OrderedDict
from heapq import heappush, heappop, heapify
from typing import List, Optional, Tuple
from functools import lru_cache
import math
import bisect
Python Gotchas for DSA
| Gotcha | Fix |
|---|---|
heapq is min-heap only | Negate values for max-heap: heappush(h, -val) |
| Lists as dict keys | Use tuple() instead |
| String concat in loop is O(n^2) | Use ''.join(list) |
| Integer division | Use // not / (returns float) |
| Negative modulo | Python: -7 % 3 = 2 (differs from C++/Java) |
| Default recursion limit | sys.setrecursionlimit(10000) for deep recursion |
| Shallow copy trap | arr[:] or list(arr) for true copy, copy.deepcopy() for nested |