DSA Crash Course
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
  • 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 .py file 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

GotchaFix
heapq is min-heap onlyNegate values for max-heap: heappush(h, -val)
Lists as dict keysUse tuple() instead
String concat in loop is O(n^2)Use ''.join(list)
Integer divisionUse // not / (returns float)
Negative moduloPython: -7 % 3 = 2 (differs from C++/Java)
Default recursion limitsys.setrecursionlimit(10000) for deep recursion
Shallow copy traparr[:] or list(arr) for true copy, copy.deepcopy() for nested