Project Workshop — DSA Patterns Cheatsheet
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Python · Algorithms · Data Structures
Expected effort: 20–32 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | two pointers (fast+slow / left+right) produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | sliding window (fixed/variable size) produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | prefix sum and Kadane's algorithm produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | binary search: all variants (first/last/answer space) produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.5 | BFS/DFS for trees and graphs produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.6 | topological sort (Kahn's / DFS) produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.7 | Union-Find (DSU) with path compression produces the specified behavior inside Arrays, strings & trees (15 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | 0/1 knapsack and unbounded knapsack produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | LCS and LIS (O(n log n) with binary search) produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | interval DP and matrix chain produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | bitmask DP for subset problems produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | digit DP for counting in ranges produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.6 | state machine DP (buy/sell stocks) produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.7 | tree DP and partition DP produces the specified behavior inside DP patterns (10 patterns) | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | Segment tree: range queries + point updates produces the specified behavior inside Advanced DSA | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | BIT (Fenwick tree): prefix sum + point updates produces the specified behavior inside Advanced DSA | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | monotonic stack and deque problems produces the specified behavior inside Advanced DSA | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | Trie: insert/search/startsWith produces the specified behavior inside Advanced DSA | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.5 | 30-day LeetCode plan: Week1-4 progression produces the specified behavior inside Advanced DSA | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | hash map counting and grouping produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | linked-list reversal/cycle/merge produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | stack/queue/heap priority patterns produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.4 | merge intervals and sweep line produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.5 | backtracking subsets/permutations/combinations produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.6 | greedy exchange argument produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.7 | matrix traversal and multi-source BFS produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.8 | shortest path Dijkstra/Bellman-Ford produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.9 | minimum spanning tree Kruskal/Prim produces the specified behavior inside Additional interview patterns | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1portfolio/2├── README.md3├── requirements-and-estimates.md4├── designs/5├── algorithms/6├── failure-analysis/7├── tests-and-benchmarks/8└── interview-talk-track.mdBuild plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Arrays, strings & trees (15 patterns) | two pointers (fast+slow / left+right); sliding window (fixed/variable size); prefix sum and Kadane's algorithm | Demonstration plus focused tests |
| 2 | DP patterns (10 patterns) | 0/1 knapsack and unbounded knapsack; LCS and LIS (O(n log n) with binary search); interval DP and matrix chain | Demonstration plus focused tests |
| 3 | Advanced DSA | Segment tree: range queries + point updates; BIT (Fenwick tree): prefix sum + point updates; monotonic stack and deque problems | Demonstration plus focused tests |
| 4 | Additional interview patterns | hash map counting and grouping; linked-list reversal/cycle/merge; stack/queue/heap priority patterns | Demonstration plus focused tests |
| 5 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1from collections import deque2
3def shortest_path(graph: list[list[int]], start: int, target: int) -> list[int]:4 parent = [-1] * len(graph)5 parent[start] = start6 queue = deque([start])7 while queue:8 node = queue.popleft()9 if node == target:10 break11 for neighbor in graph[node]:12 if parent[neighbor] == -1:13 parent[neighbor] = node14 queue.append(neighbor)15 if parent[target] == -1:16 return []17 path = []18 while target != start:19 path.append(target)20 target = parent[target]21 return [start, *reversed(path)]22
23print(shortest_path([[1, 2], [0, 3], [0, 3], [1, 2]], 0, 3))Expected result
1[0, 1, 3]Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | from collections import deque | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 3 | def shortest_path(graph: list[list[int]], start: int, target: int) -> list[int]: | Defines a function; its parameters form the explicit input boundary. |
| 4 | parent = [-1] * len(graph) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 5 | parent[start] = start | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 6 | queue = deque([start]) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 7 | while queue: | Repeats while the condition remains true; the body must make progress toward termination. |
| 8 | node = queue.popleft() | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 9 | if node == target: | Evaluates the condition and enters this branch only when it is truthy. |
| 10 | break | Implements the next python statement in the example's data flow. |
| 11 | for neighbor in graph[node]: | Consumes the iterable one item at a time through the iterator protocol. |
| 12 | if parent[neighbor] == -1: | Evaluates the condition and enters this branch only when it is truthy. |
| 13 | parent[neighbor] = node | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 14 | queue.append(neighbor) | Implements the next python statement in the example's data flow. |
| 15 | if parent[target] == -1: | Evaluates the condition and enters this branch only when it is truthy. |
| 16 | return [] | Returns the observable result to the caller and ends this invocation. |
| 17 | path = [] | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 18 | while target != start: | Repeats while the condition remains true; the body must make progress toward termination. |
| 19 | path.append(target) | Implements the next python statement in the example's data flow. |
| 20 | target = parent[target] | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 21 | return [start, *reversed(path)] | Returns the observable result to the caller and ends this invocation. |
| 23 | print(shortest_path([[1, 2], [0, 3], [0, 3], [1, 2]], 0, 3)) | Emits the example's observable output. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Arrays, strings & trees (15 patterns) | A DSA sliding window is not a distributed rate-limit window; the technique fails when its monotonic restoration assumption does not hold. | Write the invariant and complexity before code, prove termination, and test empty, duplicate, skewed, disconnected, and worst-shape inputs. |
| DP patterns (10 patterns) | A matrix chain is an algorithmic cost problem, not a GitHub Actions matrix; irrelevant dimensions cause state explosion. | State dimensions and transition cost explicitly, prove optimal substructure, and optimize memory only after identifying which prior layers remain necessary. |
| Advanced DSA | Off-by-one indexing and an incorrect merge identity are the dominant segment/Fenwick bugs. | Use them when update/query volume justifies added implementation complexity. |
| Additional interview patterns | Memorizing a template without its precondition selects sliding windows for negative sums, Dijkstra for negative edges, or greedy steps without an exchange proof. | Write the invariant and complexity before the template, then test empty, singleton, duplicate, disconnected, and worst-shape inputs. |
Engineering checklist for this stack
- To do: state the invariant before code
- To do: prove termination and transition correctness
- To do: derive time and space complexity
- To do: test empty, singleton, duplicate, and worst-case inputs
- To do: compare against a simpler baseline
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1@pytest.mark.parametrize(2 ("value", "expected"),3 [("valid", "success"), ("", "validation-error"), ("duplicate", "same-result")],4)5def test_contract(value, expected, service):6 result = service.execute(value)7 assert result.status == expected8
9def test_failure_rolls_back(repository, service):10 repository.fail_next_write()11 with pytest.raises(RepositoryError):12 service.execute("valid")13 assert repository.visible_changes() == []Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?